Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 8, 2025

This PR adds two new methods to collections in the OOW library:

  • shuffle() - Mutates the original array by shuffling its elements in place using the Fisher-Yates algorithm
  • shuffled() - Returns a new shuffled copy without modifying the original collection

Usage Examples

// shuffle() - mutates the original array
const arr = [1, 2, 3, 4, 5];
arr.shuffle();
console.log(arr); // [3, 1, 5, 2, 4] (example output)

// shuffled() - returns new shuffled copy
const original = [1, 2, 3, 4, 5];
const shuffled = original.shuffled();
console.log(original); // [1, 2, 3, 4, 5] (unchanged)
console.log(shuffled); // [2, 5, 1, 3, 4] (example output)

// Works with strings too
const word = "hello";
const shuffledWord = word.shuffled();
console.log(word);         // "hello" (unchanged)
console.log(shuffledWord); // "llohe" (example output)

Implementation Details

  • shuffle() is available only on Arrays (since it mutates the collection)
  • shuffled() is available on both Arrays and Strings (via SequenceableCollection)
  • Both methods handle edge cases like empty collections and single elements
  • Uses the Fisher-Yates shuffle algorithm for uniform random distribution
  • All existing tests continue to pass (129/129)
  • Code passes linting without errors

Fixes #48.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor Author

Copilot AI commented Sep 8, 2025

@ngarbezza 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Co-authored-by: ngarbezza <519947+ngarbezza@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [feature] Collection extension: shuffle/shuffled Implement shuffle() and shuffled() methods for collections Sep 8, 2025
@Copilot Copilot AI requested a review from ngarbezza September 8, 2025 17:09
Copilot finished work on behalf of ngarbezza September 8, 2025 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Collection extension: shuffle/shuffled

2 participants