Skip to content

Instantly share code, notes, and snippets.

@ebragaparah
Created April 4, 2016 02:15
Show Gist options
  • Save ebragaparah/d7118818ced9c01ead4b393659fc8d8a to your computer and use it in GitHub Desktop.
Save ebragaparah/d7118818ced9c01ead4b393659fc8d8a to your computer and use it in GitHub Desktop.
Check if a string ends with another.
function confirmEnding(str, target) {
var counter = 0;
strLastCharPosition = str.length - 1;
targetLastCharPosition = target.length - 1;
while (counter <= target.length &&
(target[targetLastCharPosition] === str[strLastCharPosition])) {
counter++;
strLastCharPosition--;
targetLastCharPosition--;
}
return counter === target.length;
}
@ebragaparah
Copy link
Author

Hmmm.. meh. But it's just the first approach. I want to make the same behavior using a functional one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment