File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 16
16
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
17
17
18
18
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 ( "_" ) ;
25
27
// Return the string in UPPER_SNAKE_CASE
26
- return toUpperSnakeCase ;
28
+ return result ;
27
29
}
28
30
// Example usage for this function
29
31
// let string = "hello there";
You can’t perform that action at this time.
0 commit comments