I am looking to create an array similar to the following structure using javascript:
[
52, // random number 0-100
53, // random +1 or -1
54, // random +1 or -1
53, // random +1 or -1
52, // random +1 or -1
53, // random +1 or -1
52, // random +1 or -1
51, // random +1 or -1
50, // random +1 or -1
51, // random +1 or -1
// etc., etc., etc.
]
Is there a way to achieve this?
I attempted the following approach, but it only generates random numbers followed by alternating 1's and -1's:
Array(50).fill(0).map((v, i, a) => i !== 0 ? (Math.round(Math.random()) ? a[i-1] + 1 : a[i-1] - 1) : Math.floor(Math.random() * 101))