Skip to content

Commit 32c94e5

Browse files
committed
update: Add toUpperSnakeCase function to convert strings to UPPER_SNAKE_CASE with example usage Sprint-2/3-mandatory-implement/2-cases.js
1 parent 3c47903 commit 32c94e5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Sprint-2/3-mandatory-implement/2-cases.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,36 @@
1414
// You will need to come up with an appropriate name for the function
1515
// Use the MDN string documentation to help you find a solution
1616
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17+
18+
function toUpperSnakeCase(string) {
19+
//split the string into an array of words
20+
const wordsArray = string.split(" ");
21+
// Convert each word to uppercase
22+
const upperWordsArray = wordsArray.map((word) => word.toUpperCase());
23+
// Join the array back into a string with underscores
24+
const toUpperSnakeCase = upperWordsArray.join("_");
25+
// Return the string in UPPER_SNAKE_CASE
26+
return toUpperSnakeCase;
27+
}
28+
// Example usage for this function
29+
// let string = "hello there";
30+
31+
// console.log(`The string in UPPER_SNAKE_CASE is: ${toUpperSnakeCase(string)}`);
32+
33+
console.log(
34+
`The string in UPPER_SNAKE_CASE for 'hello there' is: ${toUpperSnakeCase(
35+
"hello there"
36+
)}`
37+
);
38+
39+
console.log(
40+
`The string in UPPER_SNAKE_CASE for 'lord of the rings' is: ${toUpperSnakeCase(
41+
"lord of the rings"
42+
)}`
43+
);
44+
45+
console.log(
46+
`The string in UPPER_SNAKE_CASE for 'example usage for this function' is: ${toUpperSnakeCase(
47+
"example usage for this function"
48+
)}`
49+
);

0 commit comments

Comments
 (0)