Skip to main content

Built and signed on GitHub Actions

itertools for Deno 🦕

This package works with Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 months ago (0.3.0)
function combinationsWithReplacement
combinationsWithReplacement<T>(
iterable: Iterable<T>,
r: number,
): Generator<T[]>

Returns r-length subsequences of elements from the input iterable allowing individual elements to be repeated more than once.

Examples

Example 1

import { assertEquals } from "@std/assert";

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

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

Type Parameters

Parameters

iterable: Iterable<T>
  • The input iterable to generate combinations from
  • Length of combinations to generate

Return Type

Throws

RangeError

If r is negative or not an integer

Add Package

deno add jsr:@gabelluardo/itertools

Import symbol

import { combinationsWithReplacement } from "@gabelluardo/itertools";

---- OR ----

Import directly with a jsr specifier

import { combinationsWithReplacement } from "jsr:@gabelluardo/itertools";

Add Package

npx jsr add @gabelluardo/itertools

Import symbol

import { combinationsWithReplacement } from "@gabelluardo/itertools";

Add Package

yarn dlx jsr add @gabelluardo/itertools

Import symbol

import { combinationsWithReplacement } from "@gabelluardo/itertools";

Add Package

pnpm dlx jsr add @gabelluardo/itertools

Import symbol

import { combinationsWithReplacement } from "@gabelluardo/itertools";

Add Package

bunx jsr add @gabelluardo/itertools

Import symbol

import { combinationsWithReplacement } from "@gabelluardo/itertools";