Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active October 3, 2021 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/10670b467ac695247a56c863c820ed39 to your computer and use it in GitHub Desktop.
Save YonatanKra/10670b467ac695247a56c863c820ed39 to your computer and use it in GitHub Desktop.
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