this code is for return duplicates after sorted them, and also to return the missed value between the limits of the given array, it's executed correctly, but i need to re code it so it excecute in less time than it execute can any one help?
function findDupsMiss(arr) {
// your code here
var newarr = [];
var missed;
var duplicates = [];
var newdup = []
arr.forEach((el, i) => {
if (newarr.includes(el) == false) {
newarr.push(el)
}
})
var sortedArr = newarr.sort((a, b) => a - b);
for (var i = 0; i < sortedArr.length - 1; i++) {
if ((sortedArr[i] + 1) !== sortedArr[i + 1]) {
missed = sortedArr[i] + 1
}
}
arr.forEach(el => {
if (arr.indexOf(el) != arr.lastIndexOf(el)) {
duplicates.push(el)
}
})
duplicates.forEach(el => {
if (newdup.includes(el) == false) {
newdup.push(el)
}
})
var lastdup = newdup.sort((a, b) => a - b);
return [missed, lastdup]
}
findDupsMiss([10, 9, 8, 9, 6, 1, 2, 4, 3, 2, 5, 5, 3])