Duplicate detection algorithm in JavaScript

Here’s a super simple duplicate detection algorithm in JavaScript:

function hasDuplicate(items) {
  const seen = {};
  for (item of items) {
    if (item in seen) {
      return true;
    }
    seen[item] = true;
  }
  return false;
}

This algorithm is $O(n)$ time and $O(n)$ space.


Tech mentioned