Skip to content

Instantly share code, notes, and snippets.

@joePichardo
Created December 10, 2015 03:49
Show Gist options
  • Save joePichardo/778625aa1109b5a6f5ba to your computer and use it in GitHub Desktop.
Save joePichardo/778625aa1109b5a6f5ba to your computer and use it in GitHub Desktop.
Check if a string (first argument) ends with the given target string (second argument).
// Bonfire: Confirm the Ending
// Author: @joepichardo
// 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
//variables used for substr(start, length)
var start = str.length-target.length;
var length = target.length;
var endOfStr = str.substr(start, length);
//returns correct boolean if strings are identical
if(target === endOfStr){
return true;
}else {
return false;
}
}
end("Bastian", "n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment