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:

// typescript

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:


Webmentions & Comments

Copyright © Paramdeo Singh · Built with Jekyll in 🇬🇾 · All Rights Reserved

[ this node is permanently morphing last updated on 28 May 2023 ]

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