4.9.0 • Published 12 months ago

@tonaljs/collection v4.9.0

Weekly downloads
436
License
MIT
Repository
-
Last release
12 months ago

@tonaljs/collection tonal npm version

Functions to create and manipulate collections (collections)

Usage

ES6:

import { Collection } from "tonal";

node:

const { Collection } = require("tonal");

API

range(from: number, to: number) => number[]

Creates a numeric range:

Collection.range(-2, 2); // => [-2, -1, 0, 1, 2]
Collection.range(2, -2); // => [2, 1, 0, -1, -2]

rotate(times: number, collection: any[]) => any[]

Rotate an collection a number of times:

Collection.rotate(1, [1, 2, 3]); // => [2, 3, 1]

shuffle(collection: any[]) => any[]

Randomizes the order of the specified collection in-place, using the Fisher–Yates shuffle.

Collection.shuffle(["a", "b", "c"]);

permutations(collection: any[]) => any[][]

Get all permutations of an collection

Collection.permutations(["a", "b", "c"])) // =>
// =>
// [
//   ["a", "b", "c"],
//   ["b", "a", "c"],
//   ["b", "c", "a"],
//   ["a", "c", "b"],
//   ["c", "a", "b"],
//   ["c", "b", "a"]
// ]
4.9.0

12 months ago

4.8.1

2 years ago

4.7.2

3 years ago

4.8.0

3 years ago

4.7.1

3 years ago

4.7.3

3 years ago

4.7.0

3 years ago

4.6.10

3 years ago

4.6.2

4 years ago

4.5.1

5 years ago

4.5.0

5 years ago

3.5.3

5 years ago

3.5.2

5 years ago

3.5.1

5 years ago

3.5.0

5 years ago