Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2015 07:27
Show Gist options
  • Save anonymous/69ca7390f126e00bfd84 to your computer and use it in GitHub Desktop.
Save anonymous/69ca7390f126e00bfd84 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/kkas 's solution for Bonfire: Confirm the Ending
// Bonfire: Confirm the Ending
// Author: @kkas
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
var subStrAry,
subLen,
targetAry,
i;
if (str.length < target.length) {
return false;
}
subStrAry = str.substr(target.length * -1).split('');
subLen = subStrAry.length;
targetAry = target.split('');
for(i = 0; i < subLen; i++) {
if (subStrAry[i] !== targetAry[i]) {
return false;
}
}
return true;
}
end("Bastian", "n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment