This repository was archived by the owner on Apr 18, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathcases.js
More file actions
34 lines (24 loc) · 1.26 KB
/
cases.js
File metadata and controls
34 lines (24 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// A set of words can be written grouped together in different cases.
// For example, "hello there" in snake case would be written "hello_there"
// UPPER_SNAKE_CASE means taking a string and writing it in all capitals with underscores for spaces
// Implement a function that:
// Given a string input like "hello there"
// When we call this function with the input string
// Then it returns the string in UPPER_SNAKE_CASE, so "HELLO_THERE"
// Test case: we expect "lord of the rings" to be "LORD_OF_THE_RINGS"
// Test case: we expect "the great gatsby" to be "THE_GREAT_GATSBY"
// Test case: we expect "the da vinci code" to be "THE_DA_VINCI_CODE"
// Come up with a clear, simple name for the function
// Use the string documentation to help you plan your solution
function upperSnakeCase(inputString){
let stringWords = inputString.split(" ");
let upperCaseWords = stringWords.map(letter => letter.toUpperCase());
let underScoreWords = upperCaseWords.join("_");
return underScoreWords;
}
console.log(upperSnakeCase("lord of the rings"));
// function upperSnakeCase(inputString) {
// // Replace spaces with underscores, then convert to uppercase
// return inputString.replace(/\s+/g, '_').toUpperCase();
// }
// console.log(upperSnakeCase("lord of the rings"));