First Duplicate Value


  • The important thing to know by reading the problem is that they want the first so we will definitely not be changing the order of the array.



function firstDuplicateValue(array) {

let map = new Map()
for(let i = 0; i < array.length; i++) {
if(map.has(array[i])) {
return array[i]
} else {
return -1;




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Creating a visual regression tool for your web app

Fetch data in React using Hooks

ReactJS Girls Online #2 in Review

Barcode Generator in Laravel 8 Tutorial

Decorator design pattern in functional and object oriented programming

How to make a sponsors site with Next.js, Tailwind CSS, and Stripe 💵

Features And Breaking Changes In TypeScript 4

Writing Your Own Custom React Hooks

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nerly Ton

Nerly Ton

More from Medium

Perspective 7: Public database


E-Commerce — Automatic Building of Collection of Products

A Direct Link Between the Human Brain & Technology: Neuralink’s Link