-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathletterCapitalize.js
47 lines (33 loc) · 1.11 KB
/
letterCapitalize.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Letter Capitalize Coderbyte Problem Solution
* @summary Capitalizes the First Letter in every Word inside a String
* @link https://coderbyte.com/editor/First%20Reverse:JavaScript
* @author Tam Nguyen <[email protected]>
*/
// --- Tests ---
console.log(LetterCapitalize("hello world")); // Hello World
console.log(LetterCapitalize("i ran there")); // I Ran There
// --- Helper Functions ---
/**
* @param {String} sentence
* @param {String} sentence returns string with capitalize first letters in every word
*/
function LetterCapitalize(sentence) {
let individualWords = sentence.split(" ");
for(let i = 0; i < individualWords.length; i++) {
/** @function capitalizeFirst */
individualWords[i] = capitalizeFirst(individualWords[i]);
}
sentence = individualWords.join(" ");
return sentence;
}
/**
* @param {String} word
* @returns {String} Returns word with Capitalized First Letter
*/
function capitalizeFirst(word) {
let letter = word.split("");
letter[0] = letter[0].toUpperCase();
word = letter.join("");
return word;
}