-
Notifications
You must be signed in to change notification settings - Fork 4
/
capitalize.js
29 lines (22 loc) · 939 Bytes
/
capitalize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
Create a function that takes an array of names and returns an array with the first letter capitalized.
Examples
capitalize(["mavis", "senaida", "letty"]) ➞ ["Mavis", "Senaida", "Letty"]
capitalize(["samuel", "MABELLE", "letitia", "meridith"]) ➞ ["Samuel", "Mabelle", "Letitia", "Meridith"]
capitalize(["Slyvia", "Kristal", "Sharilyn", "Calista"]) ➞ ["Slyvia", "Kristal", "Sharilyn", "Calista"]
Notes
Don't change the order of the original array.
Notice in the second example above, "MABELLE" is returned as "Mabelle".
After writing the solution run ```npm run capitalize-test``` to test your solution
source: edabit.com
*/
function capitalize(arr) {
// Do not change anything above this line
// Write your code here
var res = arr.map(function(items) {
return items.charAt(0).toUpperCase() + items.toLowerCase().slice(1);
})
return res;
}
// Do not change anything below this line
module.exports = capitalize;