Skip to content

Commit 1b5f2cf

Browse files
committed
Convert strings to UPPER_SNAKE_CASE format
1 parent 8796b5b commit 1b5f2cf

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
// A set of words can be grouped together in different cases.
1+
// This function converts any sentence into UPPER_SNAKE_CASE
2+
function toUpperSnakeCase(input) {
3+
// Step 1: Convert the string to uppercase
4+
const upperCase = input.toUpperCase();
25

3-
// For example, "hello there" in snake case would be written "hello_there"
4-
// UPPER_SNAKE_CASE means taking a string and writing it in all caps with underscores instead of spaces.
6+
// Step 2: Replace all spaces with underscores
7+
const snakeCase = upperCase.replace(/ /g, "_");
58

6-
// Implement a function that:
9+
// Step 3: Return the result
10+
return snakeCase;
11+
}
712

8-
// Given a string input like "hello there"
9-
// When we call this function with the input string
10-
// it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE"
11-
12-
// Another example: "lord of the rings" should be "LORD_OF_THE_RINGS"
13-
14-
// You will need to come up with an appropriate name for the function
15-
// Use the MDN string documentation to help you find a solution
16-
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
13+
// Example usage:
14+
console.log(toUpperSnakeCase("hello there")); // Output: "HELLO_THERE"
15+
console.log(toUpperSnakeCase("lord of the rings")); // Output: "LORD_OF_THE_RINGS"

0 commit comments

Comments
 (0)