Day 19 of 100 Days Of Code
Day 19: August 12, Sunday
Today ‘s Progress: I continue work Intermediate Algorithm Scripting.
Thoughts: One word AAAAARRRRRRRRRGGGGHHHH!!!!! These are maddening even the solutions I looked up when I was struggling didn’t work:
console.log("Spinal Tap Case");
//Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
function spinalCase(str) {
// Replace low-upper case to low-space-uppercase
str = str.replace(/([a-z])([A-Z])/g, '$1 $2');
// Split on whitespace and underscores and join with dash
console.log(str.toLowerCase().split(/(?:_| )+/) .join('-'));
return str.toLowerCase().split(/(?:_| )+/) .join('-');
}
// Unit test:
spinalCase("This Is Spinal Tap");// should return "this-is-spinal-tap".
spinalCase("thisIsSpinalTap");// should return "this-is-spinal-tap".
spinalCase("The_Andy_Griffith_Show");// should return "the-andy-griffith-show".
spinalCase("Teletubbies say Eh-oh");// should return "teletubbies-say-eh-oh".
spinalCase("AllThe-small Things");// should return "all-the-small-things".
console.log("<----------------------next exercise------------------------->");
This one hours finally I gave up and searched for a solution and even that needed altering to get it to work… String.prototype.replace()
Link(s) to work
- Started Intermediate Algorithm Scripting.
Introduction to the Functional Programming Challenges
- PassedWherefore art thou
- PassedSpinal Tap Case
All code is in GitHub and repl.it here: repl.it IntermediateAlgorithmScripting.js or GitHub IntermediateAlgorithmScripting.js
Written on August 12, 2018