-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamelSnakeCase.js
More file actions
34 lines (26 loc) · 796 Bytes
/
Copy pathcamelSnakeCase.js
File metadata and controls
34 lines (26 loc) · 796 Bytes
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
/**
* -------------------------------------------------------
* Programming Question : A string to Camel & Snake_case.
* -------------------------------------------------------
**/
// Q. Write a function to convert a string to Camel & Snake_case.
//constraint
//?
//?
//?
//?
function toCamelCase(str) {
let splitIntoWord = str.split(" ");
let result = splitIntoWord.map((currEl,index) => {
if(index === 0){
return currEl.toLowerCase();
}else{
return currEl.charAt(0).toUpperCase() + currEl.slice(1).toLowerCase();
}
})
let snakeCase = result.join("_");
return snakeCase;
}
console.log(toCamelCase("heLlo world ganEsh"));
console.log(toCamelCase("100 Days of JavaScript Coding Challenges"));
// console.log(toCamelCase());