Skip to content

Instantly share code, notes, and snippets.

  • Save anonymous/808ba98883fb47e8b98d to your computer and use it in GitHub Desktop.
Save anonymous/808ba98883fb47e8b98d to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/rjmccallumbigl 's solution for Bonfire: Confirm the Ending
// Bonfire: Confirm the Ending
// Author: @rjmccallumbigl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending?solution=function%20end(str%2C%20target)%20%7B%0A%20%20%2F%2F%20%22Never%20give%20up%20and%20good%20luck%20will%20find%20you.%22%0A%20%20%2F%2F%20--%20Falcor%0A%20%20%0A%20%20var%20splitArray%20%3D%20str.split(%22%22)%3B%20%20%0A%20%20var%20i%20%3D%200%3B%0A%20%20%0A%20%20var%20sub%20%3D%20str.substr(-target.length)%3B%0A%20%20%0A%20%20%2F%2Freturn%20the%20bool%20if%20last%20char%20matches%20or%20not%0A%20%20%2F*if%20(splitArray%5BsplitArray.length-1%5D%20%3D%3D%20target)%7B%0A%20%20%20%20%0A%20%20%20%20return%20true%3B%0A%20%20%20%20%0A%20%20%7D%20*%2F%0A%20%20%0A%20%20%2F%2Freturn%20splitArray%5BsplitArray.length-1%5D%3B%0A%20%20%0A%20%20%0A%20%20if%20(sub%20%3D%3D%20target)%20%7B%0A%20%20%20%20%0A%20%20%20%20return%20true%3B%0A%20%20%20%20%0A%20%20%7D%20else%20%7B%0A%20%20%20%20%0A%20%20%20%20return%20false%3B%0A%20%20%20%20%0A%20%20%7D%0A%20%20%0A%20%20%0A%20%20%0A%20%20%2F%2Freturn%20splitArray%3B%0A%20%20%0A%20%20%2F%2Freturn%20str%3B%0A%7D%0A%0Aend(%22He%20has%20to%20give%20me%20a%20new%20name%22%2C%20%22name%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
var splitArray = str.split("");
var i = 0;
var sub = str.substr(-target.length);
//return the bool if last char matches or not
/*if (splitArray[splitArray.length-1] == target){
return true;
} */
//return splitArray[splitArray.length-1];
if (sub == target) {
return true;
} else {
return false;
}
//return splitArray;
//return str;
}
end("He has to give me a new name", "name");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment