1function capitalize2(str) {
2 str = str.toLowerCase();
3
4 const arrOfWords = str.split(" ");
5
6 const arrOfWordsCased = [];
7
8 for (let i = 0; i < arrOfWords.length; i++) {
9 const char = arrOfWords[i].split("");
10 char[0] = char[0].toUpperCase();
11
12 res.push(char.join(""));
13 }
14 return arrOfWordsCased.join(" ");
15}