Day 16 is to transform a given sentence into a new one with dashes between letters inside a sentence.
For Instance, a sentence hello scrimba
should have the output h-e-l-l-o s-c-r-i-m-b-a
This is the JavaScript solution
function insertDashes(arr) {
let words = arr.split(' ');
let dashes = words.map(word => word.split('').join('-')).join(' ');
return dashes;
}
Top comments (2)
I guess that is useful when creating nice URLs.
What would be your use case?
I was thinking the same thing sir, so the title of webpage which has the space will be filled with dashes on the URL just like the dev.to does