You are viewing a single comment's thread. Return to all comments →
in Js:
function sockMerchant(n, ar) { const pairsOfColors = ar.reduce((obj, num) => { obj[num] = (obj[num] || 0) + 1; return obj; }, {}); let pairs = []; for (let key in pairsOfColors) { if (!(pairsOfColors[key] <= 1) && pairsOfColors[key] % 2 === 0) { pairs.push(pairsOfColors[key] / 2); } else if (!(pairsOfColors[key] <= 1) && pairsOfColors[key] % 2 === 1) { pairs.push((pairsOfColors[key] - 1) / 2); } else { pairs.push(0); } } return pairs.reduce((acc, num) => (acc + num), 0); }
Seems like cookies are disabled on this browser, please enable them to open this website
Sales by Match
You are viewing a single comment's thread. Return to all comments →
in Js: