I need to find missing numbers in array. There are many similar questions here & i checked it all, but can't find code who works for me. The close answer to my question was:
numbers.sort((a, b) => a - b);
miss = Array.from({
length: numbers[numbers.length - 1] - numbers[0] + 1
},
(_, idx) => numbers[0] + idx)
.filter(elem => !numbers.includes(elem));
console.log(miss.join(','));
It work correctly for this cases:
numbers = [4, 3, 2, 7, 8, 2, 3, 1] // print 5, 6
numbers = [1, 2, 3, 3, 5] // print 4
But for next case:
numbers = [1, 1, 1, 1, 1, 1, 1, 1] // returns nothing
I need to return 2, 3, 4, 5, 6, 7, 8
Edit: Need to find all the integers of [1, N] inclusive that do NOT appear in this array.
missarray in case 3, before .filter is applied?