Skip to content

Instantly share code, notes, and snippets.

@NEbere
Created February 11, 2016 17:47
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 NEbere/29aff5a627b4f4b65ba3 to your computer and use it in GitHub Desktop.
Save NEbere/29aff5a627b4f4b65ba3 to your computer and use it in GitHub Desktop.
Check if a string (first argument) ends with the given target string (second argument).
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
var tagLen = target.length;
var str_len = ((-str.length) + tagLen );
var sub_str = str.substr(-tagLen, tagLen);
if(target == sub_str){
return true;
}else{
return false;
}
}
//calling the function. will return true
end("Falcon", "on");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment