html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!--
[Coding Assignment:] Letter Capitalize
Process a sentence, remove unnecessary
spaces (prevailing, trailing, extra),
capitalize all its words, output should be
a sentence.
Input / Output example :
Input : " i love soloLearn I love javaScript "
Output : "I Love SoloLearn I Love JavaScript"
-->
Enter to Rename, Shift+Enter to Preview
css
css
1
/*by @Dan&Jel*/
Enter to Rename, Shift+Enter to Preview
js
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
console.log(`[ Coding Assignment: ] Letter Capitalize
`);
const letterCapitalize = str => {
return str.trim()
.replace(/\s+/g, ' ')
.replace(/\b[a-z]/gi, (char) => {
return char.toUpperCase();
});
};
/**
* regex [a-z] matches every alphabetic
* character in the string but the \b before
* it specifies a word boundary, in other
* words, nothing can come before those
* letters therefore selecting every word
* in the string.
**/
console.log(`Input : \" i love soloLearn I love javaScript \"`);
console.log(`Output : \"${letterCapitalize(
' I love soloLearn I love javaScript ')}\"
`);
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run