-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest21.js
More file actions
24 lines (20 loc) · 699 Bytes
/
test21.js
File metadata and controls
24 lines (20 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*capitalizeWords
Write a recursive function called capitalizeWords. Given an array
of words, return a new array containing each word capitalized.
*/
// add whatever parameters you deem necessary - good luck!
// let words = ['i', 'am', 'learning', 'recursion'];
// capitalizedWords(words); // ['I', 'AM', 'LEARNING', 'RECURSION']
const capitalizeWords = arg => {
if (arg.length === 0) {
return arg;
}
let newArr = [];
let temp = arg[0].toUpperCase();
newArr.push(temp);
return newArr.concat(capitalizeWords(arg.slice(1)));
};
// console.log(capitalizeWords(['i', 'am', 'learning', 'recursion']));
const arr = ['abc', 'def'];
console.log(arr[0].toUpperCase());
console.log(arr);