NovichokJS,
function numberOfPairs(gloves) {
const obj = {};
let count = 0;
for (let el of gloves) {
obj[el] = (obj[el]||0)+1;
obj[el] %= 2;
obj[el] || count++;
}
return count;
}
console.log(numberOfPairs(["red", "green", "red", "blue", "blue"])); // 2
console.log(numberOfPairs(["gray", "green", "red", "blue", "yellow"])); // 0
console.log(numberOfPairs(["gray", "green", "red", "green", "yellow"])); // 1
console.log(numberOfPairs(["red", "red", "yellow"])); // 1
console.log(numberOfPairs(["red", "red", "red", "red", "red", "red"])); // 3