Created
February 9, 2017 07:18
-
-
Save simonhlee97/a6095b85259be981045e630a7b28a3cc to your computer and use it in GitHub Desktop.
confirmTheEnding created by simonhlee97 - https://repl.it/FdGK/0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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