Skip to content

Instantly share code, notes, and snippets.

@Vigowebs
Created February 17, 2019 07:41
Show Gist options
  • Save Vigowebs/eb355d909acdc1a497eca925b0901981 to your computer and use it in GitHub Desktop.
Save Vigowebs/eb355d909acdc1a497eca925b0901981 to your computer and use it in GitHub Desktop.
function missingNumber(arr){
var n = arr.length+1,
sum = 0,
expectedSum = n* (n+1)/2;
sum = arr.reduce((total, num) => total + num);
return expectedSum - sum;
}
missingNumber([5, 2, 6, 1, 3]);
// 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment