Skip to content

polidario/shuffle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”€ shuffle

A lightweight utility to shuffle the elements of an array in place using the Fisher–Yates algorithm.


πŸš€ Installation

Install via npm:

npm install @bernardpolidario/shuffle

πŸ“¦ Usage

const shuffleArray = require('@bernardpolidario/shuffle');

const items = ['apple', 'banana', 'cherry', 'date'];
const shuffled = shuffleArray(items);

console.log(shuffled); 
// β†’ [ 'cherry', 'apple', 'date', 'banana' ] (order will vary)

⚠️ Note: The original array is mutated. If you want to preserve the original, clone it first:

const shuffled = shuffleArray([...items]);

🧠 How It Works

This package uses the Fisher–Yates shuffle, a time-tested algorithm that ensures every possible ordering of the array is equally likely.


πŸ“„ API

shuffleArray(array)

  • Parameters:
    • array β€” An array of any type (e.g. strings, numbers, objects).
  • Returns:
    • The same array, shuffled in place.

βœ… Example Use Cases

  • Randomizing quiz options
  • Shuffling playlist items
  • Mixing flashcards
  • Creating randomized test data

πŸ”§ Development

To test this package locally:

npm link
# then in another project
npm link @bernardpolidario/shuffle

πŸ“œ License

MIT Β© 2025 Your Name

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published