Skip to content
Let’s talk
Data structures & algorithms

SOLVED & EXPLAINED – Finding duplicates (JavaScript) | Data Structures & Algorithm

1 min read

SOLVED & EXPLAINED – Finding duplicates  (JavaScript) | Data Structures & Algorithm

QUESTION

A duplicate is a number whose value appeared earlier in the list. Given a list of numbers, return an array with all the duplicates in the order that they appear. (Duplicates that appear multiple times should be printed multiple times). Use Ruby’s Set class to solve the challenge. Example const arr = [1, 2, 3, 1, 5, 6, 7, 8, 5, 2] console.log(find_duplicates(arr)) // = [1, 5, 2]

 

Share this article LinkedIn WhatsApp X

Written by Eloghene Otiede

Software engineer, full-stack developer and tech tutor. More about me

Leave a comment

Your email address will not be published. Required fields are marked *