Skip to content

Commit c3f25c2

Browse files
upperSnake solution
1 parent 3200170 commit c3f25c2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,19 @@
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 toUpperSnakeCase(str) {
19+
20+
return str.toUpperCase().split('').map(function(c) {
21+
// splits string into individual characters and maps each character to a new value
22+
23+
return /[A-Z0-9]/.test(c) ? c : '_';
24+
// checks if the character is an uppercase letter or a digit
25+
26+
}).join('');
27+
// joins the array of characters back into a single string and replaces spaces with underscores
28+
}
29+
30+
console.log(toUpperSnakeCase("there-once was/a young lady from+London"));
31+
console.log(toUpperSnakeCase("hello.world! test+123"));
32+

0 commit comments

Comments
 (0)