Forked from anonymous/bonfire-confirm-the-ending.js
Created
December 7, 2015 15:57
-
-
Save robertsheacole/37f711398dab74463db8 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/robertsheacole 's solution for Bonfire: Confirm the Ending
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
// 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