Confirm the Ending 1234

Tell us what’s happening: Hey guys I was trying to do this excersize confirm the ending of string by giving target string and testing string. I cant figure out whats the problem in my code why it is not giving true for given result.

Your code so far

function confirmEnding(str, target) {
  //var arr=[];
  var arr=str.split(" ");//split the string into array
  var teststr=arr[arr.length-1];//taking last string of array as test string
  var teststrarr=[];
  for(var i=teststr.length-1;i>=0;i--){//making array of test string and pushing it into test string array
    teststrarr.push(teststr[i]);
  
    }
  var targetarr=target.split('').reverse();//making target string as array and reversing it to make comaprison 
  
  /*teststrarr.filter(function(a){
    if(teststrarr[a]==target[a]);
    return teststrarr[a];
  });*/
  var teststrarr2=[];
  
 for(var j=0;j<teststrarr.length-1;j++){//comapring elements of both teststr array and targetarr and put the matched elements in new array teststrarr2
    if(teststrarr[j]==target[j]){
      teststrarr2.push(targetarr[j]);
    }
   if(teststrarr2.join('')==targetarr.join('')){//joining both arrays and comparing if compared it will be true otherwise false
     return true;
   }
  else{
  return false;
  }
  
}
}

confirmEnding("open sesame", "same");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36.

Link to the challenge: