Skip to content

Instantly share code, notes, and snippets.

@jgresalfi
Created September 9, 2016 02:52
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 jgresalfi/3934d6286fec7b79ea01431c032b0378 to your computer and use it in GitHub Desktop.
Save jgresalfi/3934d6286fec7b79ea01431c032b0378 to your computer and use it in GitHub Desktop.
Confirm the Ending...match arg2 string with end of arg1 string...or don't...
function confirmEnding(str, target) {
var fragCount = target.length,
chunk = str.substring(str.length - fragCount);
if (chunk === target) {
return true;
} else { return false; }
}
confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification");
@jgresalfi
Copy link
Author

jgresalfi commented Sep 9, 2016

Or with a ternary:

function confirmEnding(str, target) {
  var fragCount = target.length,
      chunk = str.substring(str.length - fragCount),
      result = (chunk === target) ? true : false;
  return result;
}

confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment