This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Josh Ackerman
Posted May 24 - Read on Facebook

Hello,
I am trying to "shuffle" an array of numbers in FramerJS. To my understanding the fastest way to do this is with the Fisher-Yates Shuffle (see http://bost.ocks.org/mike/shuffle/ or http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).

I am wondering how to run this in FramerJS, considering I cannot seem to use a while loop?

This algorithm involves the following JavaScript code.

function shuffle(array) {
var m = array.length, t, i;
while (m) {
i = Math.floor(Math.random() * m--);
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}

6 Comments

Jordan Robert Dobson

I don't think you can do while loops.

Josh Ackerman

Yes, I noticed that the editor will not accept them? Is there some alternative way I could achieve this effect?

Jordan Robert Dobson

Well just do a for loop checking if m is 0 and make sure to decrement m every loop. They do it m--.

Jordan Robert Dobson

Utils has a random method.

George Kedenburg III
Koen Bok

Remember we include lodash by default: _.shuffle

Read the entire post on Facebook