function numberOfPairs(gloves) { let tmp = {}, count = 0; for (let item of gloves) { tmp[item] = ++tmp[item] || 1; count += 1 - tmp[item] % 2; } return count; }