Skip to content

Instantly share code, notes, and snippets.

@19h47
Last active April 2, 2018 16:51
Show Gist options
  • Save 19h47/4caacab6cc72f6af12a9674feafb5285 to your computer and use it in GitHub Desktop.
Save 19h47/4caacab6cc72f6af12a9674feafb5285 to your computer and use it in GitHub Desktop.
Check if a string ends with a given string target
/**
* Confirm endings
*
* Check if a string ends with a given target
*
* @param String string
* @param String target A target to match with the given string
*/
function confirmEnding(string, target) {
return string.substr(-target.length) === target ? true : false;
}
// Used
confirmEnding("Bastian", "n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment