Trying to print out any values that are duplicates. Having an issue visualizing what I need to do. This isn't working.
This is different than any other similar question because I want all the duplicate values to be printed, not just ones that have duplicates.
Could you also give the time/space complexity of the result as well?
This should print out 2, 2, 4, 4, 7, 7
const printDuplicates = (arr) => {
let newArray = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i] === arr[i] + 1) {
newArray.push(arr[i]);
}
}
return newArray
}
console.log(printDuplicates([1, 2, 2, 4, 4, 5, 6, 7, 7, 8, 9]));
And BTW I APPRECIATE ALL THE HELP