• I have the "right answer", but fail submission

Question related to mission Sort Array by Element Frequency

 

Screenshot attached: the failed test case presented seems identical to the one in the assertions below the problem. I pass this test, no matter what editor I try (Atom, CheckIO, Repl.it), and the displayed "correct" case doesn't seem to be correct itself. Am I missing something? here is my messy code:

function frequencySort(items){
      if ( items.length <= 1){return items};

  var obj=  {}; //for counting
  var arr = []; //new arr to collect  numbers, in order of appearance, without repeats

  for (var i =0 ; i < items.length ; i ++){
    if( obj[items[i]] == undefined ){ obj[items[i]]= 1 } 
      else if ( obj[items[i]] !== undefined){obj[items[i]]++}  
    if( arr.indexOf( items[i] ) == -1  ){arr.push(items[i])}
  }
//sort for overall order( reduce to unique numbers((arr)), then sort)

    items.sort(function(a, b){ return obj[b] - obj[a];})//sort for frequency, based off of obj

 var arr2 = [];//should hold correctly ordered items
for ( var i = 0 ; i < arr.length ; i ++){
  for ( var j = 0; j < items.length; j ++){
    if(items[j] == arr[i]){  arr2.push(items[j])}
  }
}
    return arr2;
}