Skip to content

Instantly share code, notes, and snippets.

@orrisroot
Last active June 11, 2025 03:47
Show Gist options
  • Select an option

  • Save orrisroot/e32a9358c53324c217875af5353f972e to your computer and use it in GitHub Desktop.

Select an option

Save orrisroot/e32a9358c53324c217875af5353f972e to your computer and use it in GitHub Desktop.
Whether an array has duplicate elements
const hasDuplicate = <T,>(items: T[], func: (a: T, b: T) => boolean = (a, b) => a === b): boolean => {
return items.find((item, idx) => items.some((item2, idx2) => func(item, item2) && idx !== idx2)) != null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment