Created
February 17, 2019 07:41
-
-
Save Vigowebs/eb355d909acdc1a497eca925b0901981 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 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