Instructions:
Complete the solution so that the function will break up camel casing, using a space between words.
Example
"camelCasing" => "camel Casing"
"identifier" => "identifier"
"" => ""
Solution:
function solution(string) {
return arr = string.split('').map(l => l !== l.toUpperCase() ? l : ' ' + l).join('');
}
Thoughts:
1.I transform the string into an array to be able to iterate easily through each letter/element of the array.
2.I use the function map in order to go through each letter and transformed it based on the condition: l !==l.toUpperCase()
.If the original letter is not upper case we return the letter as it is, in case it is upper case , we add a space before the upper letter.
- I join the array to a string and return it .
Top comments (0)