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!

--

--

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