Skip to content

Commit 9577ac5

Browse files
committed
Change small letter into capital letter
1 parent e29954a commit 9577ac5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,25 @@
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 to convert a string to UPPER_SNAKE_CASE
19+
function toUpperSnakeCase(str) {
20+
// Replace spaces with underscores and convert to uppercase
21+
return str.replace(/\s+/g, "_").toUpperCase();
22+
}
23+
24+
// Example usage:
25+
console.log(toUpperSnakeCase("hello there")); // Output: "HELLO_THERE"
26+
console.log(toUpperSnakeCase("lord of the rings")); // Output: "LORD_OF_THE_RINGS"
27+
console.log(toUpperSnakeCase("javascript is fun")); // Output: "JAVASCRIPT_IS_FUN"
28+
29+
/**
30+
Explanation:
31+
32+
str.replace(/\s+/g, "_") replaces all whitespace (spaces, tabs, etc.) with underscores.
33+
34+
.toUpperCase() converts the resulting string to uppercase letters.
35+
36+
The function returns the final string in UPPER_SNAKE_CASE
37+
*/
38+

0 commit comments

Comments
 (0)