function numberOfPairs(gloves) { let tmp = {}; for (let item of gloves) tmp[item] = ++tmp[item] || 1; return Object.values(tmp).reduce((a, v) => a + Math.floor(v / 2), 0); }