Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save easierbycode/1827803 to your computer and use it in GitHub Desktop.
Save easierbycode/1827803 to your computer and use it in GitHub Desktop.
sum of any combination eqls largest number
// http://coderbyte.com/CodingArea/Results.php?ct=Array%20Addition%20I
function ArrayAdditionI(arr) {
var sumEqualToMember = false;
var max = Math.max.apply({},arr);
for(i=0; i<=arr.length; i++) {
var sum = arr[i];
for(n=0; n<=arr.length; n++) {
if(n!==i) { sum+=arr[n] }
if(sum === max) {
sumEqualToMember = true;
}
for(x=0; x<=arr.length; x++) {
if( x!==i && (sum - arr[x]) == max) {
sumEqualToMember = true;
}
}
}
}
return sumEqualToMember;
}
console.log( ArrayAdditionI([4,6,23,10,1,3]) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment