1/**
2 * @param {number[]} nums
3 * @return {number}
4 */
5
6var singleNumber = function(nums) {
7 const record = {};
8 nums.forEach(value => {
9 record[value] = (record[value] || 0) + 1;
10 });
11
12 for (let k of Object.keys(record)) {
13 if(record[k] === 1) return parseInt(k);
14 }
15};
16
17ensureEqual(singleNumber([2,2,1]), 1, 'test 1');
18ensureEqual(singleNumber([4,1,2,1,2]), 4, 'test 2');