4.8.3 • Published 3 months ago

@tonaljs/array v4.8.3

Weekly downloads
400
License
MIT
Repository
-
Last release
3 months ago

@tonaljs/array tonal npm version

A collection of functions to create and manipulate arrays of notes or intervals.

API

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

Creates a numeric range:

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

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

Rotate an array a number of times:

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

sortedNoteNames(array: any[]) => string[]

Sort an array of note names in ascending order. Pitch classes are listed before notes. Any string that is not a note is removed.

sortedNoteNames(["c2", "c5", "c1", "c0", "c6", "c"]);
// => ['C', 'C0', 'C1', 'C2', 'C5', 'C6']
sortedNoteNames(["c", "F", "G", "a", "b", "h", "J"]);
// => ['C', 'F', 'G', 'A', 'B']

sortedUniqNoteNames(array: any[]) => string[]

Return a list of sorted note names with duplications removed.

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

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

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

Get all permutations of an array

permutations(["a", "b", "c"])) // =>
// =>
// [
//   ["a", "b", "c"],
//   ["b", "a", "c"],
//   ["b", "c", "a"],
//   ["a", "c", "b"],
//   ["c", "a", "b"],
//   ["c", "b", "a"]
// ]
4.8.3

3 months ago

4.8.2

3 months ago

4.8.1

4 months ago

4.7.2

1 year ago

4.8.0

1 year ago

4.7.3

1 year ago

4.6.11

1 year ago

4.6.12

1 year ago

4.6.10

1 year ago

4.6.5

3 years ago

4.6.2

3 years ago

4.5.1

3 years ago

4.5.0

3 years ago

3.2.9

4 years ago

3.2.8

4 years ago

3.2.6

4 years ago

3.2.7

4 years ago

3.2.5

4 years ago

3.2.4

4 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago