I’ve been having trouble with this challenge for a while now. The one test case I have not been able to pass is confirmEnding("Open sesame", "same") should return true
. For some reason, it returns false, and when I checked to see what returns instead of false, it returns “ame” and just skips over “same”. Any reason why?
Here is my code:
function confirmEnding(str, target) {
var arr = str.split(" ");
var compare = arr[arr.length - 1];
for (var i = 0; i < compare.length; i++) {
compare = compare.substr(i);
if (compare === target) {
return true;
}
}
return false;
EDIT:
Here is what’s showing up in the console when I see what prints for each compare. Why does it skip “same”? Or is something else happening here?