Skip to content

Instantly share code, notes, and snippets.

@linstantnoodles
Created December 2, 2013 17:28
Show Gist options
  • Save linstantnoodles/7753125 to your computer and use it in GitHub Desktop.
Save linstantnoodles/7753125 to your computer and use it in GitHub Desktop.
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