-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.js
27 lines (24 loc) · 861 Bytes
/
temp.js
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
function spinalCase(str) {
//split creates an array and allow you to use array methods. Join makes it a string again.
//str.split('').map(isLetter(a)).join('');
//var tempArr = str.trim().replace(/ +/g, "").split('');
var tempArr = str.trim().split('');
var newStr = [];
tempArr.forEach(element => {
if (element.toUpperCase() != element.toLowerCase()) {
newStr.push(element.toLowerCase());
}
else if (element == " ") {
newStr.push('-');
}
else {
newStr.push('-');
}
});
return newStr.join('').replace(/,/g,"");
console.log(newStr.join('').replace(/,/g,""));
}
spinalCase("AllThe-small Things");
//spinalCase("Teletubbies say Eh-oh")
//spinalCase('The_Andy_Griffith_Show');
//spinalCase('This Is Spinal Tap');