Skip to content

Commit 3cd9638

Browse files
committed
Implemented toUpperSnakeCase() function for converting strings to UPPER_SNAKE_CASE
1 parent 2ce418b commit 3cd9638

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,22 @@
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+
// MDN References I used:
19+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function
20+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
21+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim
22+
23+
function toUpperSnakeCase(input) {
24+
return input
25+
// Removes extra spaces
26+
.trim()
27+
// Converts everything to caps
28+
.toUpperCase()
29+
// Replaces all spaces with underscores
30+
// g means global, so it applies to the whole string
31+
// / / is a regular expression matching a space
32+
.replace(/ /g, "_");
33+
}
34+
35+
console.log(toUpperSnakeCase("hello there")); // HELLO_THERE

0 commit comments

Comments
 (0)