Created
December 2, 2013 17:28
-
-
Save linstantnoodles/7753125 to your computer and use it in GitHub Desktop.
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
function ArrayAdditionI(arr) { | |
var valMap = {}; // Cache sums | |
arr.sort(function(a,b) { return a - b;}); | |
var largestNum = arr.pop(); | |
for (var i = 0; i < arr.length; i++) { | |
var combos = Object.keys(valMap); | |
for (var j = 0; j < combos.length; j++) { | |
var newCombo = arr[i] + (+combos[j]); | |
if (newCombo === largestNum) return "true"; | |
valMap[newCombo] = true; | |
} | |
// Include current val in our set | |
valMap[arr[i]] = true; | |
} | |
return "false"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment