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' ]
CodePudding user response:
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"));