DEV Community

Cover image for Day 16 of JavaScriptmas - Insert Dashes

Day 16 of JavaScriptmas - Insert Dashes

Keep moving forward. Learn well not learn fast.
・1 min read

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 = => word.split('').join('-')).join(' ');

    return dashes;
Enter fullscreen mode Exit fullscreen mode

Discussion (2)

bias profile image
Tobias Nickel

I guess that is useful when creating nice URLs.

What would be your use case?

flyingduck92 profile image
Sekti Author

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 does