Confirm the Ending having trouble with tests

Tell us what’s happening:

I’ve already completed this challenge with a bit of code that passed the tests but didn’t really do what was asked for. This code works when I manually call for the function to complete but when I press ctrl+enter or the run tests button a couple of them fail.

Is this a problem with my code or something else?

Thanks for any help you can provide.

Your code so far

var strArr = [];
var tarArr = [];
function confirmEnding(str, target) {
  var arrayStrRev = str.split("").reverse();
  var arrayTargetRev = target.split("").reverse();
  for (var i=0; i<target.length; i++){
    strArr.unshift(arrayStrRev[i]);
    tarArr.unshift(arrayTargetRev[i]);   }
  var strComp = strArr.join("");
  var tarComp = tarArr.join("");
  if (strComp == tarComp){return true;}
  return false;
}
confirmEnding("", "");
//confirmEnding("He has to give me a new name", "name"); returns as true for me but fails the test
//confirmEnding("Open sesame", "same"); returns as true for me but fails the test
//confirmEnding("Bastian", "n"); returns true but if I write something like confirmEnding("horse", "cow") that would fail the tests it fails the tests which is weird.
//another note, if the target is two words I wouldn't be able to have any true answers, I'd have to remove special marks and convert everything to lowercase.```
**Your browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (X11; CrOS x86_64 9901.66.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.82 Safari/537.36```.

**Link to the challenge:**
https://www.freecodecamp.org/challenges/confirm-the-ending

By declaring the following outside the function, they will retain the values they had during the previous test when the next test starts. The FCC tests are ran consecutively.

var strArr = [];
var tarArr = [];

Thank you for the insight and the speed. Moved em down and that solved everything.