You are viewing a single comment's thread. Return to all comments →
// Using map --> create map // key--> item, value --> occurences of item in input array (a) // iterate through map --> return key whose value is 1
let numMap = new Map() a.forEach(item=> { if(numMap.has(item)){ numMap.set(item,numMap.get(item)+1) } else { numMap.set(item,1) } }) for (let [key,value] of numMap) { if(value===1) { return key} }
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer
You are viewing a single comment's thread. Return to all comments →
// Using map --> create map // key--> item, value --> occurences of item in input array (a) // iterate through map --> return key whose value is 1