-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuppercase.js
More file actions
23 lines (17 loc) · 925 Bytes
/
uppercase.js
File metadata and controls
23 lines (17 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function upper(str){
var words = str.toLowerCase().split(" ") // every is lowercase
for (var i = 0; i < words.length; i++){
words[i] = words[i][0].toUpperCase() +
words[i].slice(1)
// console.log(words[i]) give each of the loop output one by one until it ends
// words[i] = words[i][0].toUpperCase() will give us the first letter in every words uppercased "H I A E O C S T U"
// words[i] = words[i].slice(1) this will remove the first letter from the string.
//ex. "ere s n xample f onvert trings o ppercase"
}
return words.join(" ");
}
upper('Here is an example of Convert Strings to Uppercase');
// another solution
return str .toLowerCase().split(' ').map(word => word[0].toUpperCase() + word.substr(1).join('')
return str.replace(/\b[a-z]/gi, function(char){ return char.toUpperCase(); });
//word boundary backslash \b rangeof a-z (g global i case sensitive)