Created
February 14, 2012 16:10
-
-
Save easierbycode/1827803 to your computer and use it in GitHub Desktop.
sum of any combination eqls largest number
This file contains hidden or 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
// 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