Need help in "translating" jiter into JS

Thank you.

If I implement the code like this

jitters = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0];
function shuffle(a) { var j, x, i; for (i = a.length - 1; i > 0; i--) { j = Math.floor(Math.random() * (i + 1)); x = a[i]; a[i] = a[j]; a[j] = x; } return a;} 
util.shuffle(jitters);
current_jitter = jitters.pop();

it works on the pavlovia. But it takes the values with replacement apparently. I think the problem in defining was that the shuffling should happen on

if ([0].includes(loop_pract.thisN)) {

or

if ([0].includes(n)) {

if I introduce a counter n

or

if (n = 0)

But none of these is working. How else could I make it shuffle the values without replacement (so each of the values should be twice as in the initial list). Now I have them as

1
1
0.1
0.1
0.1
0.3
0.3
0.4
0.5
0.5
0.5
0.6
0.8
0.8
0.8
0.8
0.8
0.8
0.9
0.9

Thousand thanks!

You’re almost there! :slight_smile:

I guess what happens is that your jitters get reconstructed and shuffled every before you pop it. You should only construct and shuffle it once. If you put it in a routine before any loops, you should be able to achieve that. Now, to get a grip on what’s happening, try adding console.log statements everywhere (that you can see in the browser console). Very handy for debugging.

you are a genious! It seems to be working

1
1
0.1
0.1
0.2
0.2
0.3
0.3
0.4
0.4
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.9
0.9

Yes I am ;). Kudos for your persistence!

What choice do you I have except being persistant? :smiley: Thanks and sorry for getting on your nerves.

1 Like

You got my hint when I didn’t reply to this post :wink: