File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments