Skip to content

Instantly share code, notes, and snippets.

@simonhlee97
Created February 9, 2017 07:18
Show Gist options
  • Save simonhlee97/a6095b85259be981045e630a7b28a3cc to your computer and use it in GitHub Desktop.
Save simonhlee97/a6095b85259be981045e630a7b28a3cc to your computer and use it in GitHub Desktop.
confirmTheEnding created by simonhlee97 - https://repl.it/FdGK/0
function confirmEnding(str, target) {
return str.substr(target.length) === target;
}
confirmEnding("sesame", "same");
// why does the code above return "FALSE"?
// I originally thought, since (-target.length = -4)
// that "does substr(-target.length) === target?" meant does 'same' = the last 4 characters of str? but (-4) is actually an index, so you start at -4th letter, which is 's' and you go to the end, which gives you "same".
/*
function confirmEnding(str, target) {
return str.substr(-target.length) === target;
}
confirmEnding("simon", "sim");
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment