01 Apr 2023

Use a Set to Decide Whether an Array of Numbers has any Duplicates

Taken from Execute Program

Write a hasDuplicates function. It should use a set to decide whether an array of numbers has any duplicates. It should return true if there are duplicates; otherwise it should return false.


This is the answer I came up with:

function hasDuplicates(numbers: Array<any>) {
  let tempSet = new Set()
  for (let number of numbers) {
    if (tempSet.has(number)) {
      return true
  return false


Solution tested in REPL:


Copyright © Paramdeo Singh · All Rights Reserved · Built with Jekyll

This node last updated November 7, 2023 and is permanently morphing...

Paramdeo Singh Guyana

Generalist. Edgerunner. Riding the wave of consciousness in this treacherous mortal sea.

Technology Design Strategy Literature Personal Blogs
Search Site

Results are from Blog, Link Dumps, and #99Problems