DEV Community

Cover image for Day 16 of JavaScriptmas - Insert Dashes
Sekti Wicaksono
Sekti Wicaksono

Posted on

Day 16 of JavaScriptmas - Insert Dashes

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;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
bias profile image
Tobias Nickel

I guess that is useful when creating nice URLs.

What would be your use case?

Collapse
 
flyingduck92 profile image
Sekti Wicaksono

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