Skip to content

Instantly share code, notes, and snippets.

@sebshub
Created December 2, 2016 21:55
Show Gist options
  • Save sebshub/97e78b55468744058c11cbc447b19cbc to your computer and use it in GitHub Desktop.
Save sebshub/97e78b55468744058c11cbc447b19cbc to your computer and use it in GitHub Desktop.
Confirm the Ending "FCC" Check if a string (first argument, str) ends with the given target string (second argument, target) without using .endsWith()
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
var x = str.length - (target.length);
if (str.substr(x, str.length) == target) {
return true;
} else {
return false;
}
/*function confirmEnding(str, target) {
return str.substr(-target.length) === target;
}*/
}
confirmEnding("Bastian", "n");
@sebshub
Copy link
Author

sebshub commented Dec 2, 2016

Confirm the Ending freecodecamp.com exercise
"FCC" Check if a string (first argument, str) ends with the given target string (second argument, target) without using .endsWith()

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