{"id":21913251,"url":"https://github.com/kevinhermawan/shuffly","last_synced_at":"2025-04-16T06:40:36.505Z","repository":{"id":65231813,"uuid":"587361123","full_name":"kevinhermawan/shuffly","owner":"kevinhermawan","description":"A JavaScript utility for shuffling arrays","archived":false,"fork":false,"pushed_at":"2023-08-31T11:36:11.000Z","size":477,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T05:11:20.208Z","etag":null,"topics":["fisher-yates-shuffle","javascript","knuth-shuffle","permutation","random","sattolo-cycle","shuffle","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/shuffly","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinhermawan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-10T15:17:30.000Z","updated_at":"2023-01-13T09:41:42.000Z","dependencies_parsed_at":"2024-12-06T17:43:31.339Z","dependency_job_id":null,"html_url":"https://github.com/kevinhermawan/shuffly","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhermawan%2Fshuffly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhermawan%2Fshuffly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhermawan%2Fshuffly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhermawan%2Fshuffly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinhermawan","download_url":"https://codeload.github.com/kevinhermawan/shuffly/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249209284,"owners_count":21230465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fisher-yates-shuffle","javascript","knuth-shuffle","permutation","random","sattolo-cycle","shuffle","typescript"],"created_at":"2024-11-28T18:15:24.149Z","updated_at":"2025-04-16T06:40:36.483Z","avatar_url":"https://github.com/kevinhermawan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shuffly\n\n![Minified size](https://img.shields.io/bundlephobia/min/shuffly) ![Test coverage](https://img.shields.io/codecov/c/github/kevinhermawan/shuffly) ![Monthly download](https://img.shields.io/npm/dm/shuffly)\n\nShuffly is a JavaScript utility that provides various functions for shuffling arrays. It includes both the [Fisher-Yates](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) and [Sattolo](https://rosettacode.org/wiki/Sattolo_cycle) algorithms for generating unique permutations and for repeated permutations respectively.\n\n## Features\n\n- Supports Fisher-Yates \u0026 Sattolo algorithms\n- Supports Deno via NPM\n- Zero dependencies\n\n## Installation\n\nTo install `shuffly`, run the following command:\n\n**NPM**\n\n```\nnpm install shuffly\n```\n\n**Yarn**\n\n```\nyarn add shuffly\n```\n\n**pnpm**\n\n```\npnpm add shuffly\n```\n\n## Usage\n\n### shuffle\n\n```ts\nimport { shuffle } from \"shuffly\";\n// import { shuffle } from \"npm:shuffly\"; // (for Deno)\n\nconst array = [1, 2, 3, 4, 5];\nconst shuffledArray = shuffle(array);\n\nconsole.log(shuffledArray); // [1, 3, 5, 2, 4] (shuffled)\n```\n\nThe `shuffle` function is an implementation of the Fisher-Yates shuffle algorithm, which is a widely used algorithm for shuffling elements in an array randomly. The Fisher-Yates shuffle algorithm works by iterating through the array starting from the last element and swapping each element with a randomly chosen element from the remaining unshuffled portion of the array.\n\n**Syntax**\n\n```ts\nshuffle\u003cT\u003e(array: T[]): T[]\n```\n\n**Time complexity**\n\n\u003e O(n), where n is the length of the array.\n\n### shuffleUnique\n\n```ts\nimport { shuffleUnique } from \"shuffly\";\n// import { shuffleUnique } from \"npm:shuffly\"; // (for Deno)\n\nconst array = [1, 2, 3, 4, 5];\nconst shuffledArray = shuffleUnique(array);\n\nconsole.log(shuffledArray); // [2, 4, 1, 5, 3] (shuffled)\n```\n\nThe `shuffleUnique` function is an implementation of the Sattolo algorithm, which is a variant of the Fisher-Yates shuffle algorithm that guarantees that no repeated permutations are generated when shuffling an array. This means that after the shuffling is done, the elements in the array will be in a random order, but that order will be unique and different from all other possible orders of the same elements.\n\n**Syntax**\n\n```ts\nshuffleUnique\u003cT\u003e(array: T[]): T[]\n```\n\n**Time complexity**\n\n\u003e O(n), where n is the length of the array.\n\n## License\n\n[MIT License](/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinhermawan%2Fshuffly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinhermawan%2Fshuffly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinhermawan%2Fshuffly/lists"}