Skip to main content
Latest
function combinations
import { combinations } from "https://deno.land/x/masx200_leetcode_test@10.6.5/deps.ts";

Yields r length Arrays from the input iterable. Order of selection does not matter and elements are chosen without replacement.

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

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

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

Parameters

iterable: Iterable<T>
r: number

Returns

Generator<T[]>