Solving Popular Algorithms: Number of Good Pairs

What our algorithm needs to say to the pairs…
nums = [1,2,3,1,1,3]
var numIdenticalPairs = function(nums) {
let results = []

for (let i = 0; i < nums.length; i++) {
for (let j = 1; j < nums.length; j++) {
if (nums[i] === nums[j] && i < j) {
let goodPair = []
goodPair.push(i,j)
results.push(goodPair)
}
}
}

return results.length

};
Thumbs up for trying this problem on your own!

--

--

--

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

Recommended from Medium

JavaScript | Learning algorithm in JavaScript from scratch

Deploy Your React/Node app to Heroku in 15 minutes or less. (3 steps)

Azure Static Web Apps — first impression and how to deploy your existing static web app for FREE

Postman Part II

Electron’s ‘remote’ module considered harmful

JavaScript Object.entries() method

function taking w/an array & a number argument. returns a value from the array list occurring a ‘number’ amount of times

Learn to use zircle-ui by building a smarthome dashboard UI

2 Excellent Websites For Web Developers

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
HopeGiometti

HopeGiometti

More from Medium

Data Structures, Algorithms, And Big O Notation! A Beginners Guide.

Setup Ruby on R

ARRAYS AND STRINGS DATA STRUCTURES.

5/14 leet code