Find Duplicate in Array
ZeeshanAli-0704
Posted on September 21, 2022
const removeExactlyOneDuplicate = (arr) => {
let map = new Map();
for (let i = 0; i < arr.length; i++) {
if (!map.has(arr[i])) {
map.set(arr[i], 1);
} else {
return arr[i];
}
}
};
// console.log(removeExactlyOneDuplicate([1, 3, 4, 2, 2]));
console.log(removeExactlyOneDuplicate([3, 1, 3, 4, 2]));
💖 💪 🙅 🚩
ZeeshanAli-0704
Posted on September 21, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.