Skip to content

Commit 98b0e74

Browse files
committed
update: testing alternative way by apply convert to upre case, then spit and join
1 parent 2d292bb commit 98b0e74

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
1717

1818
function toUpperSnakeCase(string) {
19-
//split the string into an array of words
20-
const wordsArray = string.split(" ");
21-
// Convert each word to uppercase
22-
const upperWordsArray = wordsArray.map((word) => word.toUpperCase());
23-
// Join the array back into a string with underscores
24-
const toUpperSnakeCase = upperWordsArray.join("_");
19+
// First convert the entire string to uppercase
20+
const upperCaseString = string.toUpperCase();
21+
22+
// Then split it into words (assuming space-separated)
23+
const wordsArray = upperCaseString.split(" ");
24+
25+
// Then join the array into a string using underscores
26+
const result = wordsArray.join("_");
2527
// Return the string in UPPER_SNAKE_CASE
26-
return toUpperSnakeCase;
28+
return result;
2729
}
2830
// Example usage for this function
2931
// let string = "hello there";

0 commit comments

Comments
 (0)