Answer the question
In order to leave comments, you need to log in
How to add from zero to a certain number in a progression, in a certain number of steps in Javascript?
Hello!
I need to build a hyperbolic graph and for this I need an array of data.
I have a number, let's say 42, how to make it so that in 10 steps this number from zero reaches the desired value and increases exponentially ?
Each iteration must be pushed into an array.
That's what was smart enough, but here is a linear progression:
var target = 42;
var dataArr = [];
var modif = 0;
var iters = 10;
for (var i = 0; i <= iters; i++) {
dataArr.push(modif);
modif = modif + target / iters ;
}
Answer the question
In order to leave comments, you need to log in
Managed to get the desired result with this code:
var target = 42;
target = target+1;
var dataArr = [];
var modif = target;
var iters = 10;
for (var i = 0; i <= iters; i++) {
var resutl = modif;
dataArr.push(resutl - 1);
modif = Math.pow(modif, 0.7);
}
console.log(dataArr)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question