{"version":3,"file":"shuffle-JGIwrFGv.cjs","names":[],"sources":["../src/functions/shuffle/shuffle.ts"],"sourcesContent":["import type { Maybe } from '../../types';\n\n/**\n * Returns a new array with elements randomly reordered using the Fisher-Yates algorithm.\n * Does not mutate the input array.\n * @param array The array to shuffle.\n * @returns A new array with the same elements in a random order.\n * @example\n * ```ts\n * shuffle([1, 2, 3, 4]) // e.g. [3, 1, 4, 2]\n * shuffle([]) // []\n * shuffle(null) // []\n * shuffle(undefined) // []\n * ```\n */\nexport function shuffle<T>(array: Maybe<readonly T[]>): T[] {\n  const result = [...(array ?? [])];\n\n  for (let i = result.length - 1; i > 0; i--) {\n    const j = Math.floor(Math.random() * (i + 1));\n    // biome-ignore lint/style/noNonNullAssertion: indices i and j are guaranteed to be within bounds\n    [result[i], result[j]] = [result[j]!, result[i]!];\n  }\n\n  return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,QAAW,OAAiC;CAC1D,MAAM,SAAS,CAAC,GAAI,SAAS,EAAE,CAAE;AAEjC,MAAK,IAAI,IAAI,OAAO,SAAS,GAAG,IAAI,GAAG,KAAK;EAC1C,MAAM,IAAI,KAAK,MAAM,KAAK,QAAQ,IAAI,IAAI,GAAG;AAE7C,GAAC,OAAO,IAAI,OAAO,MAAM,CAAC,OAAO,IAAK,OAAO,GAAI;;AAGnD,QAAO"}