Skip to content

Instantly share code, notes, and snippets.

@piqueen314
Created December 11, 2015 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piqueen314/3da630acee0274d3e838 to your computer and use it in GitHub Desktop.
Save piqueen314/3da630acee0274d3e838 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: @piqueen314
// 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
lenStr=str.length;
lenTar=target.length;
if(str.substr(lenStr-lenTar,lenTar)==target)
{
return true;
}
return false;
}
end("Bastian", "n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment