DEV Community

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

Posted on

1

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

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more