Shuffles an array using the Fisher-Yates algorithm and optionally returns a subset
This function creates a shuffled copy of the input array without modifying the original. Optionally returns only the first N elements from the shuffled array.
The array to shuffle
Optional
Optional number of elements to return from shuffled array
Shuffled array or subset of shuffled array
const recipes = [recipe1, recipe2, recipe3, recipe4, recipe5];const shuffled = fisherYatesShuffle(recipes, 3); // Returns 3 random recipes Copy
const recipes = [recipe1, recipe2, recipe3, recipe4, recipe5];const shuffled = fisherYatesShuffle(recipes, 3); // Returns 3 random recipes
Shuffles an array using the Fisher-Yates algorithm and optionally returns a subset
This function creates a shuffled copy of the input array without modifying the original. Optionally returns only the first N elements from the shuffled array.