Add array after you read the first [closed]

0

Add array after you read the first one. example the for travels the array and divides it by the scale, then must travel the 2 but must add the first, then travels the 3 and adds the 1 and the second. then he crosses the 3 and adds the 1 and the second. and so on until it's over.

    
asked by Eduard Zora 09.02.2017 в 18:25
source

1 answer

1

Try this:

var arrText = [1, 2, 3, 4, 5];
var escala = 2;
var distancia, aux = 0;

for(var i = 0; i < arrText.length; i++){
	distancia = (arrText[i] + aux) / escala;
	aux = aux + arrText[i];

	console.log('Suma de array, posicion: '+i+', total:', aux);
}

Greetings,

    
answered by 09.02.2017 / 18:29
source