var findDisappearedNumbers = function(nums) {
let len = nums.length, disNums = [], count = 1, i = 0;
nums = [...new Set(nums)];
nums.sort((a,b) => {return a - b;});
while (i < nums.length) { // 当数组中的元素与count元素相等时才接着往下遍历数组,否则就将count存进返回的结果数组中
if (nums[i] != count) {
disNums.push(count);
} else {
i++;
}
count++;
}
while(disNums.length < len - nums.length) { // 当缺失的是末尾的数字时,通过几个数组长度的比较,判断是否需往结果数组中添加元素
disNums.push(count);
count++;
}
return disNums;
};
console.log(findDisappearedNumbers([4,3,2,7,7,2,3,1]));
console