Last active
October 3, 2021 07:13
-
-
Save YonatanKra/10670b467ac695247a56c863c820ed39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findUniqueNumber(nums) { | |
let memo = {}; | |
for (let i = 0; i < nums.length; i++) { | |
const num = nums[i]; | |
if (!memo[num]) { | |
memo[num] = 1; | |
} else { | |
memo[num] += 1; | |
} | |
} | |
return Object.keys(memo).reduce((unique,num) => { | |
return memo[num] === 1 ? Number(num) : unique; | |
}, NaN); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment