function PairOfSocks(arr) {
var obj = {}
for (var i = 0; i < arr.length; i++) {
if (obj[arr[i]] == undefined) {
obj[arr[i]] = 1
} else {
obj[arr[i]] = obj[arr[i]] + 1
}
}
var count = 0
for (var item in obj) {
var scount = Math.floor(obj[item] / 2)
count = count + scount
}
return count
}
var input = [1,2,1,2,1,3,2, 2, 0, 0]
var result = PairOfSocks(input)
console.log("result",result)
No comments:
Post a Comment