Instructions:
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
Examples (Input -> Output):
- "String" -> "SSttrriinngg"
- "Hello World" -> "HHeelllloo WWoorrlldd"
- "1234!_ " -> "11223344!!__ "
Thoughts:
- I transform the string to an array and split it into individual letters.
- I use the map() method to replace each letter to a double letter and join the array to a string.
Solution:
function doubleChar(str) {
const array = str
.split("")
.map((arr) => arr.replace(arr, arr + arr))
.join("");
return array;
}
Top comments (0)