Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Function that takes a string and returns an array with the length of each word added to each element

I tried split() to make an array out of it then map() to add numbers next to the strings.

function nameLength(str) {
    const words = str.split(" ");
    return words.map(str => $(words) $(words.length));
}

console.log(nameLength("hawaii pizza"));

was expecting:

[ 'hawaii 6', 'pizza 5' ]

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are returning the wrong string. also your syntax is also wrong
just try this

function nameLength(str) {
    const words = str.split(" ");
    return words.map(str => `${str} ${str.length}`);
}

console.log(nameLength("hawaii pizza"));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading