Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2015 15:57
Show Gist options
  • Save anonymous/a24dcffa7e94f4c568a5 to your computer and use it in GitHub Desktop.
Save anonymous/a24dcffa7e94f4c568a5 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/robertsheacole 's solution for Bonfire: Confirm the Ending
// Bonfire: Confirm the Ending
// Author: @robertsheacole
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target)
{
str = str.split('');
if (str.length > 1){
str = str.slice(Math.max(str.length - 2, 0));
str = str.join('');
} else {
str = str[str.length - 1].substr(-1);
}
target = target.split('');
if (target.length > 1) {
target = target.slice(Math.max(target.length - 2, 0));
target = target.join('');
} else {
target = target[target.length - 1].substr(-1);
str = str.slice(Math.max(str.length - 1, 0));
}
if (str === target) {
return true;
} else {
return false;
}
}
console.log(end("He has to give me a new namen", "n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment