Created
December 2, 2016 21:55
-
-
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()
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 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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()