Socket
Socket
Sign inDemoInstall

immutable-shuffle

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    immutable-shuffle

fisher-yates shuffle for immutable.js lists


Version published
Weekly downloads
4
decreased by-42.86%
Maintainers
1
Install size
138 kB
Created
Weekly downloads
 

Readme

Source

immutable-shuffle

Fisher-Yates shuffle for immutable.js

Immutable.js is an awesome, but does not provide a way to shuffle lists out of the box.

This module implements Fisher-Yates Shuffle for immutable.js. Some say it is the only way to shuffle an array in JavaScript.

Table of Contents

Install

npm install immutable-shuffle

Usage

import shuffle from 'immutable-shuffle';

const list = Immutable.fromJS([1, 2, 3, 4, 5]);
const shuffled = shuffle(list);

Performance

A naive shuffle could be implemented as follows:

const shuffled = list.sortBy(Math.random);

Compared to a fisher-yates shuffle this implementation is much slower.
On a Macbook Air 2013:

array of 100 elements
naive: 2.503ms
fisher-yates: 0.568ms

array of 1000 elements
naive: 10.218ms
fisher-yates: 4.500ms

array of 10000 elements
naive: 30.075ms
fisher-yates: 13.920ms

array of 100000 elements
naive: 357.804ms
fisher-yates: 84.567ms

array of 1000000 elements
naive: 2877.592ms
fisher-yates: 833.101ms

Contribute

PRs are very welcome.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © Tobias Kloht

Keywords

FAQs

Last updated on 20 Dec 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc