Skip to main content
The Deno 2 Release Candidate is here
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function permutations
import { permutations } from "https://deno.land/std@0.158.0/collections/mod.ts";

Builds all possible orders of all elements in the given array Ignores equality of elements, meaning this will always return the same number of permutations for a given length of input.

Example:

import { permutations } from "https://deno.land/std@0.158.0/collections/permutations.ts";
import { assertEquals } from "https://deno.land/std@0.158.0/testing/asserts.ts";

const numbers = [ 1, 2 ]
const windows = permutations(numbers)

assertEquals(windows, [
    [ 1, 2 ],
    [ 2, 1 ],
])

Parameters

inputArray: readonly T[]