Skip to main content
Module

x/combinatorics/permutations_with_replacement.ts>permutationsWithReplacement

🦕 Combinatorial generators including combinations, permutations, combinations with replacement, permutations with replacement, cartesian products, and power sets.
Latest
function permutationsWithReplacement
import { permutationsWithReplacement } from "https://deno.land/x/combinatorics@1.1.2/permutations_with_replacement.ts";

Yields r length Arrays from the input iterable. Order of selection is important and elements are chosen with replacement.

import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import { permutationsWithReplacement } from "https://deno.land/x/combinatorics/mod.ts";

const sequences = [...permutationsWithReplacement([1, 2, 3, 4], 2)];

assertEquals(sequences, [
  [1, 1], [1, 2], [1, 3], [1, 4],
  [2, 1], [2, 2], [2, 3], [2, 4],
  [3, 1], [3, 2], [3, 3], [3, 4],
  [4, 1], [4, 2], [4, 3], [4, 4],
]);

Parameters

iterable: Iterable<T>
r: number

Returns

Generator<T[]>