1const capitalize = s => {
2 s = s.split('')
3 let finalArr = []
4 let i = 0
5 while(i < 2){
6 let str = ''
7 s.forEach((letter, index) => {
8 if(i % 2 === 0 && index % 2 === 0) str += letter.toUpperCase()
9 else if(i % 2 !== 0 && index % 2 !== 0) str += letter.toUpperCase()
10 else str += letter
11 })
12
13 finalArr.push(str)
14 i++
15 }
16 return finalArr
17};
18console.log(capitalize("abcdef"))
1function capitalize1(str) {
2 const arrOfWords = str.split(" ");
3 const arrOfWordsCased = [];
4
5 for (let i = 0; i < arrOfWords.length; i++) {
6 const word = arrOfWords[i];
7 arrOfWordsCased.push(word[0].toUpperCase() + word.slice(1).toLowerCase());
8 }
9
10 return arrOfWordsCased.join(" ");
11}