function solution(statues) {
  statues.sort()
  let fullArray = [];
  let missingStatues = [];
  for (let i = Math.min(...statues); i <= Math.max(...statues); i++) {
    fullArray.push(i);
  }
  for (let i = 0; i < fullArray.length; i++) {
    if (!(fullArray[i] in statues)) {
      missingStatues.push(fullArray[i]);
    }
  }
  let missingStatuesCount = missingStatues.length;
  return missingStatues;
}
console.log(solution([6, 2, 3, 8]))I was expecting [4, 5, 7] but I got [4, 5, 6, 7, 8]. The loop that pushes fullArray[i] into missingStatues, is also pushing [6] and [8], which are in statues and should not be pushed.
 
     
    