Escape from code illusion
Sometimes we fall into illusion of performant code. It happened to me recently. This is what the case. Problem: Identify unique values in an array of values where all items appear exactly twice but one. Super simple right? I wrote the following two different solutions . Solution 1: var singleNumber = function(nums) { return Object.keys(nums.reduce((acc, item) => { if(typeof(acc[item]) !== 'undefined') { delete acc[item]; } else { acc[item] = item; } return acc; },{}))[0]; }; Solution 2: var singleNumber = function(nums) { return nums.reduce((acc, item) => acc ^ item); }; What your choice? mine was the first one. When I compare...