Skip to content

Commit f2c68a9

Browse files
committed
Add more one example as stated by CJ Yuan volunteer
1 parent da83341 commit f2c68a9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ function toUpperSnakeCase(str) {
2222
}
2323

2424
// 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"
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"
2828

2929
/**
3030
Explanation:
@@ -36,3 +36,16 @@ str.replace(/\s+/g, "_") replaces all whitespace (spaces, tabs, etc.) with under
3636
The function returns the final string in UPPER_SNAKE_CASE
3737
*/
3838

39+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
40+
// This ensures consistent results even if the input has extra spaces.
41+
42+
function toUpperCamelCase(str) {
43+
return str.trim().replace(/\s+/g, "_").toUpperCase();
44+
}
45+
46+
// Example usage:
47+
console.log(toUpperCamelCase(" hello there ")); // "HELLO_THERE"
48+
console.log(toUpperCamelCase("hello there")); // "HELLO_THERE" - The example stated by CJ Yuan volunteer
49+
console.log(toUpperCamelCase("lord of the rings")); // "LORD_OF_THE_RINGS"
50+
console.log(toUpperCamelCase("javascript is fun")); // "JAVASCRIPT_IS_FUN"
51+

0 commit comments

Comments
 (0)