Friday, June 3, 2016

Confirm the Ending--My solution

/* var test = "He has to give me a new name";


var joinedarray = "He has to give me a new name".split(" ").join("").lastIndexOf("name");
var t = "He has to give me a new name".split(" ").join("").length - "name".length;
console.log(joinedarray);
console.log(t); */


function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
 
  var joinedarrayindex = str.split(" ").join("").lastIndexOf(target);
  var test = str.split(" ").join("").length - target.length;
   if(test == joinedarrayindex){
    return true;
   }
   else{
    return false;
   }
  //return str;
}

confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain");

No comments:

Post a Comment