Skip to content

Instantly share code, notes, and snippets.

@Rahul-Sagore
Created June 9, 2018 22:14
Show Gist options
  • Save Rahul-Sagore/912ee2be14f6c6eafe17db8511b7cffd to your computer and use it in GitHub Desktop.
Save Rahul-Sagore/912ee2be14f6c6eafe17db8511b7cffd to your computer and use it in GitHub Desktop.
// Find missing number in sorted array
//[1, 2, 3, 6] => 5
function findMissingNumber(arr){
var len = arr.length;
var totalSum = (len * (len + 1))/2
return totalSum - arr.reduce((acc, curr) => acc + curr, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment