I got a number that can range be either 10, 20, 30, 40... up until 100.
I'd like to make an array from that number. The array should be structured as follows:
If the number is 10, the array should be: [0, 1, 2, 3 ... 10]
If the number is 20, the array should be: [0, 2, 4, 6 ... 20]
If the number is 30, the array should be: [0, 3, 6, 9 ... 30]
Currently, this is my code:
const max = 30
let labels = []
let count = 0
for (let i = 0; i < 10 + 1; i++) {
labels.push(count)
count += max/10
}
//[0,3,6,9,12,15,18,21,24,27,30]
This works, but I feel like it can be achieved with fewer lines of code.
I tried something like this:
let f = 0
const arr = Array.from(Array(11), (_, i) => f+=3)
//[3,6,9,12,15,18,21,24,27,30,33]
But as you can see, the output is not correct.
How can I refactor this?