Confirm the Ending helppp

Confirm the Ending helppp
0

#1

i completed this tests
confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") should return false.

but there is a challenge same as this one that isnt checking,there are two identical tests but one is completed and one is not.This one involves many tests so i cant post them here but only four tests are left .
Is there any problem with my code?

Your code so far


function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  let num = target.length;
  let num1 = str.length;
  let arr = str.split('');
  if (arr[arr.length-target.length] == target)
  {str = true;}
  else{
    str = false;
  }
  return str;
}

confirmEnding("Bastian", "n");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending/


#2
  1. Reverse the string using split() , reverse() , join() methods.
  2. Then use the the split() method again with the limit of the length of your target string.
  3. use reverse() method to make it’s direction right and then join() method to make this array into a string.
  4. Then check this string with your target string.
function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  var target_len = target.length;

  var newstr = str.split("").reverse().join("").split("",target_len).reverse().join("");

  if(newstr === target){
    return true;
  }
  else{
    return false;
  }
}

confirmEnding("Bastian", "n");