function fn(arr){ var obj = Object.create(null), i = arr.length, max = 0; while(i--){ if(arr[i] > max){ while(++max < arr[i]) obj[max] = true; }else{ delete obj[arr[i]]; } } return Object.keys(obj); }