Created
February 11, 2016 17:47
-
-
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).
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
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