Created
December 10, 2015 03:49
-
-
Save joePichardo/778625aa1109b5a6f5ba 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
// Bonfire: Confirm the Ending | |
// Author: @joepichardo | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function end(str, target) { | |
// "Never give up and good luck will find you." | |
// -- Falcor | |
//variables used for substr(start, length) | |
var start = str.length-target.length; | |
var length = target.length; | |
var endOfStr = str.substr(start, length); | |
//returns correct boolean if strings are identical | |
if(target === endOfStr){ | |
return true; | |
}else { | |
return false; | |
} | |
} | |
end("Bastian", "n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment