arrays - Find Missing Number in a Range- Javascript challenge -


can me started on challenge:

given array of 99,999 unique numbers ranging 1 100,00 in random order, find 1 number missing list.

i'm not sure how start thinking it.

except missing number, describing arithmetic progression, has nifty formula calculate sum. loop on array, sum it, , subtract formula. difference missing element:

function missing(arr) {     var sum = 0;     (var = 0, len = arr.length; < len; ++i) {         sum += arr[i];     }     var expected = 100000 * (1 + 100000) / 2;     var missing = expected - sum;     return missing; } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -