Hello! I have a little problem with the spinal tap challenge. In this I try to convert all the underscores to spaces for further parsing, but it treats the underscore as a separate character (and puts dashes around it.) Does anyone know what’s going on? Thanks!
Oh, and here’s my code.
return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
};
function isUpperCase(strng) {
return strng == strng.toUpperCase();
}
function removeSpaces(arr) {
var newArr = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i] !== " ") {
newArr.push(arr[i]);
}
}
return newArr;
}
function replaceChars(replacer, replacee) {
var newString = "";
for (var i = 0; i < replacee.length; i++) {
if (replacee[i] == replacer) {
newString += " ";
console.log(replacee[i]);
} else {
newString += replacee[i].toLowerCase();
}
}
return replacee;
}
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
var replaced1 = replaceChars("_", str);
console.log(replaced1);
var replaced2 = replaceChars("-", replaced1);
var chararray = removeSpaces(replaced2.split(""));
var words = [""];
var currentWordIndex = 0;
chararray[0] = chararray[0].toLowerCase();
for (var i = 0; i < chararray.length; i++) {
if (isUpperCase(chararray[i])) {
currentWordIndex++;
words.push("");
words[currentWordIndex] += chararray[i].toLowerCase();
} else {
words[currentWordIndex] += chararray[i];
}
}
return words.join("-");
}
console.log(spinalCase('The_Andy_Griffith_Show'));
console.log("DONE DONE DONE");