Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/itertools/itertools.ts>permutations

🦕 A TypeScript port of Python's itertools and more-itertools for Deno
Go to Latest
function permutations
import { permutations } from "https://deno.land/x/itertools@v1.1.1/itertools.ts";

Return successive r-length permutations of elements in the iterable.

If r is not specified, then r defaults to the length of the iterable and all possible full-length permutations are generated.

Permutations are emitted in lexicographic sort order. So, if the input iterable is sorted, the permutation tuples will be produced in sorted order.

Elements are treated as unique based on their position, not on their value. So if the input elements are unique, there will be no repeat values in each permutation.

Parameters

iterable: Iterable<T>
r: Maybe<number>

Returns

Iterable<Array<T>>