Array Addtion
Take an array of numbers and return true if any combo of numbers can be added up to the largest number in the array, otherwise return false. The array will not be empty, will not contain all the same elements, and may contain negative numbers.
by Jason Land
JavaScript
//Take an array of numbers and return true if any combo of numbers can be added up to the largest number in the array, otherwise return false. The array will not be empty, will not contain all the same elements, and may contain negative numbers.
function arrayAddition(arr){
var largest = "";
for(i = 0; i < arr.length; i++){
var lTest = arr.slice(i, i+1);
var masterSum = masterSum + lTest;
if(lTest > largest){
var largest = lTest;
}
}
var arraySum = masterSum - largest;
if(arraySum == largest){
alert("true");
return true;
}
}
arrayAddition([2, 5, 9, 14, 30]);