Reputation: 1923
What is an performant implementation of lodash's shuffle function ( or similar) to shuffle an Immutable List without using from/toJs()?
Upvotes: 3
Views: 1782
Reputation: 10837
Try this -
list = list.sortBy(Math.random)
This is very crude, but explains the idea which is to re-position items with a certain degree of randomness. Now you should be able to provider different comparator implementation instead of the plain vanilla random to influence a shuffle flavor.
Upvotes: 5
Reputation: 1213
I used the random-js shuffle function.
import Random from 'random-js';
let shuffled = (Random().shuffle(list.toArray()));
Upvotes: 1