Skip to content

Instantly share code, notes, and snippets.

@natafaye
Created March 5, 2022 21:06
Show Gist options
  • Save natafaye/78215da66e66d0434bc2b465d1d77817 to your computer and use it in GitHub Desktop.
Save natafaye/78215da66e66d0434bc2b465d1d77817 to your computer and use it in GitHub Desktop.
// https://www.codewars.com/kata/56b1f01c247c01db92000076/train/javascript
function doubleChar(str) {
let result = "";
// loop over the string
for(let i = 0; i < str.length; i++) {
// get the character that we're at for this looping
const character = str[i];
// add the doubled character to the result
result += character + character;
}
return result;
}
// The fancy map way :)
function doubleChar(str) {
return str.split('').map(character => character + character).join('')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment