ThorbenA
ThorbenA

Reputation: 1923

How to shuffle a ImmutableJS List

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

Answers (2)

hazardous
hazardous

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

homebrand
homebrand

Reputation: 1213

I used the random-js shuffle function.

import Random from 'random-js';

let shuffled = (Random().shuffle(list.toArray()));

Upvotes: 1

Related Questions