Programming Questions

Array Addition Getting Error

Hey guys, can anyone help me find the error here? Thank you in advance.

```
function ArrayAdditionI(arr) {
// code goes here
//for (var i =0; i< arr.length;i++ )
var orden= arr.sort(function(a, b)
{return b-a}
);
var max= Math.max(orden);
var quitarmax = orden.copyWithin(0,1);
var sumat = 0;
for (var i=0; i< quitarmax.length-1 ;i++) {
sumat = quitarmax[i]+sumat;
if (sumat === max)
{return "true"}
else
{return "false"}
}
return orden;
}
// keep this function call here
ArrayAdditionI(readline());
```

ge00rge
posted this question on 4/12/17 **|**

0

You need to add more conditional logic and iterate over "all the possible combinations" of the indexes--whereas in your above code you're simply just adding up all the indexes and then checking if it equals the max number. You can accomplish this with nested looping for the most straight forward solution.

TheMachineHerald

answered on 10/14/18

Log in to write an answer.