Skip to content

Commit 120c3f7

Browse files
committed
done cases.js
1 parent 0a8af10 commit 120c3f7

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Sprint-2/implement/cases.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,62 @@
1313

1414
// You will need to come up with an appropriate name for the function
1515
// Use the string documentation to help you find a solution
16+
17+
18+
19+
// ================== Strings in UpperCase =====================
20+
21+
function convertUpperCaseString(str) {
22+
let UPPER_SNAKE_CASE = "";
23+
// console.log(typeof str);
24+
25+
for (let i = 0; i < str.length; i++) {
26+
if (str[i] === " ") {
27+
UPPER_SNAKE_CASE += "_";
28+
} else UPPER_SNAKE_CASE += str[i].toUpperCase();;
29+
}
30+
31+
return UPPER_SNAKE_CASE;
32+
}
33+
34+
console.log(convertUpperCaseString("hola there"));
35+
36+
// ================ First letter capitalized ===================
37+
38+
39+
function firstLetterCapitalized1(str) {
40+
let result = "";
41+
for (let i = 0; i < str.length; i++) {
42+
if (i === 0 || str[i - 1] === " ") {
43+
result += str[i].toUpperCase();
44+
} else {
45+
result += str[i];
46+
}
47+
}
48+
return result;
49+
}
50+
51+
console.log(firstLetterCapitalized1("first letter capitalized"));
52+
53+
54+
// ================ Last letter capitalized ===================
55+
56+
let quote = 'He said, "It\'s a sunny day!"';
57+
58+
function lastLetterCapitalized(str) {
59+
let result = "";
60+
61+
for (let i = 0; i < str.length; i++) {
62+
if (str[i + 1] === " " || i === str.length - 1) {
63+
result += str[i].toUpperCase();
64+
} else {
65+
result += str[i];
66+
}
67+
}
68+
69+
return result;
70+
}
71+
72+
console.log(lastLetterCapitalized(`hola there ${quote}`));
73+
74+

0 commit comments

Comments
 (0)