Functions to create and manipulate collections (collections)
ES6:
import { Collection } from "@tonaljs/tonal";
node:
const { Collection } = require("@tonaljs/tonal");
Creates a numeric range:
Collection.range(-2, 2); // => [-2, -1, 0, 1, 2]
Collection.range(2, -2); // => [2, 1, 0, -1, -2]
Rotate an collection a number of times:
Collection.rotate(1, [1, 2, 3]); // => [2, 3, 1]
Randomizes the order of the specified collection in-place, using the Fisher–Yates shuffle.
Collection.shuffle(["a", "b", "c"]);
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"]
// ]