Skip to content

Instantly share code, notes, and snippets.

@Smakar20
Created September 11, 2017 23:36
Show Gist options
  • Save Smakar20/1de4c3d07b44c063459ab128f7c20425 to your computer and use it in GitHub Desktop.
Save Smakar20/1de4c3d07b44c063459ab128f7c20425 to your computer and use it in GitHub Desktop.
null created by smakar20 - https://repl.it/Kx1O/0
function ArrayAdditionI(arr) {
// code goes here
var sortedArr = arr.sort(function(a, b) {
return a - b}), sum = 0, numMap = {}
console.log("sortedArr: ", sortedArr)
for(var i = 0; i< sortedArr.length-1; i++){
sum += sortedArr[i]
numMap[sortedArr[i]] = sortedArr[i]
if(sum == sortedArr[sortedArr.length-1] || numMap[sum - sortedArr[sortedArr.length-1]] != undefined) return "true"
}
return "false"
}
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