Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MinSomai/d82d3e2271e4c5060f42985f6159b3a0 to your computer and use it in GitHub Desktop.
Save MinSomai/d82d3e2271e4c5060f42985f6159b3a0 to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Spinal Tap Case
function spinalCase(str) {
let reg = /([A-Z]*[a-z]+)/g;
let result = [];
str.match(reg).forEach(item=>{
result.push(item.toLowerCase());
})
return result.join("-");
}
console.log(spinalCase('AllThe-small Things'));
console.log(spinalCase('thisIsSpinalTap'));
console.log(spinalCase('Teletubbies say Eh-oh'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment