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

Build an Autocomplete widget with React and Elastic Search

Stripe payment form with ReactJS and Material-ui — Part 2

React.js fundamental

Using React Native For Web in Production at Curai

Implementing section logout in a react-native application

Build a Cryptocurrency Tracker Using Vue.js

4 JavaScript ES2021 (ES 12) Features That You Should Learn in 2021

Photo by Izzy Gerosa on Unsplash. Decorative.

The Web smallest DOM diffing library

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

Basic things to know about “Application Framework”

!Comment your code

As a programmer, care about semantics

BASIC Necessities