import { combinationsWithReplacement } from "https://deno.land/x/combinatorics@1.1.2/combinations_with_replacement.ts";
Yields r
length Arrays
from the input iterable
. Order of selection is not
important and elements are chosen with replacement.
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import { combinationsWithReplacement } from "https://deno.land/x/combinatorics/mod.ts";
const sequences = [...combinationsWithReplacement([1, 2, 3, 4], 2)];
assertEquals(sequences, [
[1, 1],
[1, 2],
[1, 3],
[1, 4],
[2, 2],
[2, 3],
[2, 4],
[3, 3],
[3, 4],
[4, 4],
]);
Parameters
iterable: Iterable<T>