Find Duplicate in Array

zeeshanali0704

ZeeshanAli-0704

Posted on September 21, 2022

Find Duplicate in Array
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]));


Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
zeeshanali0704
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.

Related

Sort 0, 1, 2
javascript Sort 0, 1, 2

September 21, 2022

Find Duplicate in Array
javascript Find Duplicate in Array

September 21, 2022