Skip to content

Commit 6e2a97e

Browse files
committed
Implemented the function called toUpperSnakeCase.
1 parent f813ae6 commit 6e2a97e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111

1212
// Another example: "lord of the rings" should be "LORD_OF_THE_RINGS"
1313

14+
function toUpperSnakeCase(input) {
15+
return input.toUpperCase().replace(/ /g, "_");
16+
}
17+
18+
console.log(toUpperSnakeCase("hello there")); // "HELLO_THERE"
19+
console.log(toUpperSnakeCase("lord of the rings")); // "LORD_OF_THE_RINGS"
20+
// in the above code, we are using the toUpperCase method to convert the string to uppercase
21+
// and then using the replace method to replace spaces with underscores.
22+
// This is a simple implementation of the function to convert a string to UPPER_SNAKE_CASE.
23+
// here replace(/ /g, "_") is used to replace all spaces in the string with underscores.
24+
1425
// You will need to come up with an appropriate name for the function
1526
// Use the MDN string documentation to help you find a solution
1627
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase

0 commit comments

Comments
 (0)