function generateHashtag(str) {
const words = str.split(" ");
for (let i = 0; i < words.length; i++) {
words[i] = words[i][0].toUpperCase() + words[i].substr(1);
}
words.join(" ");
return words
}
console.log(generateHashtag("i am a good coder"))
This is the code I have come up with but after iterating the string, the output is an array with the first words capitalized. How do I join up the words from the array to form back the sentence without the spaces?
2
Answers
Array#join()
returns a newstring
. Return that value directly instead of calling it onwords
without assignment.From developer.mozilla.org
words.join() creates a new value, it doesn’t update the words value.
Try this:
Here we return words.join(‘ ‘)