Last active
May 5, 2020 22:56
-
-
Save rakibulalam/f0d430c3e4c157e63316e883ebdf8caa to your computer and use it in GitHub Desktop.
Sock Merchant Hacker Rank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sockMerchant(n, ar) { | |
const pairs={}; | |
return ar.reduce((memo,value)=>{ | |
if(pairs.hasOwnProperty(value)) | |
{ | |
pairs[value]=pairs[value]+1; | |
memo+=pairs[value]%2===0?1:0 | |
}else{ | |
pairs[value]=1 | |
} | |
return memo; | |
},0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment