Where to put the .join in this function in order to rejoin the separated strings of an array

Viewed 22

Problem to solve is to capitlize the first letter of each word in a string using '.split' '.map' and 'join'. Currently implemented split and map to get the word capitlised and rejoined it, but confused as to where I need to put the .join.

Expected: "The Lord Of The Rings"
Received: ["The", "Lord", "Of", "The", "Rings"]

function titleCase(string) {
  return string.split(' ').map(word => word.charAt(0).toUpperCase() + word.substr(1))
  

}

1 Answers

First: split the string

Second: Capitalize word

Third: Join words

return string.split(' ').map(word => word.charAt(0).toUpperCase() + word.substr(1)).join(' ');
Related