https://leetcode.com/problems/single-number/
Solution 1
/**
* @param {number[]} nums
* @return {number}
*/
var singleNumber = function (nums) {
let hashMap = {};
for (let i = 0; i < nums.length; i++) {
const currentNum = nums[i];
if (hashMap[currentNum]) {
hashMap[currentNum]++;
} else {
hashMap[currentNum] = 1;
}
}
return Number(getKeybyValue(hashMap, 1));
};
const getKeybyValue = (object, value) => {
return Object.keys(object).find((key) => object[key] === value);
};