Skip to content

Instantly share code, notes, and snippets.

@YashdalfTheGray
Created April 13, 2016 23:55
Show Gist options
  • Save YashdalfTheGray/703d88c94cb656ea2f8c6599be7a86f2 to your computer and use it in GitHub Desktop.
Save YashdalfTheGray/703d88c94cb656ea2f8c6599be7a86f2 to your computer and use it in GitHub Desktop.
Finding the missing element in a non-sorted array of consecutive numbers
module.exports = (array, lowerBound, upperBound) => {
var partialSum = ((array.length + 1) * (lowerBound + upperBound)) / 2;
var sum = array.reduce((acc, i) => { return acc + i; }, 0);
return partialSum - sum;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment