(-10).abs(); // => 10 [ -2, -1, 0, 1, 2 ].abs(); // => [ 2, 1, 0, 1, 2 ]
[1,2,3].add(4); // => [ 1, 2, 3, 4 ]
[1, 2, 3, 4].addAll([7, 8, 9]); // => [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
[1, 2, 3, 4].addFirst(999); // [ 999, 2, 3, 4 ]
[0.5, 1, 2].ampdb(); // => [ -6.0205, 0, 6.0205 ]
[1, 2, 3, 4].any("even"); // => true [1, 2, 3, 4].any(function(x) { return x > 10; }); // => false
(1).asArray(); // => [ 1 ] [1, 2, 3].asArray(); // => [ 1, 2, 3 ]
(0).asBoolean(); // false (1).asBoolean(); // true [ ].asBoolean(); // false [0].asBoolean(); // true
"0.5".asFloat(); // => 0.5 [1, 2, 3.14].asFloat(); // => [1, 2, 3.14]
(1).asFunction()(); // => 1
"0.5".asInteger(); // => 0 [1, 2, 3.14].asInteger(); // => [1, 2, 3]
(true).asNumber(); // => 1 ["a", 10, 3.14].asNumber(); => 10
x = [10,20,30]; y = [0,0,2,2,1]; x.at(y); // returns [ 10, 10, 30, 30, 20 ]
[2, 5, 6].blendAt(0.4); // => 3.2
[1, 2, 3, 4].choose();
[ -0.6, -0.3, 0, 0.3, 0.6 ].clip(-0.5, 0.5); // => [ -0.5, -0.3, 0, 0.3, 0.5 ]
[ -0.6, -0.3, 0, 0.3, 0.6 ].clip2(0.5); // => [ -0.5, -0.3, 0, 0.3, 0.5 ]
at
, but values for index greater than the size of the Array will be clipped to the last index.[ 1, 2, 3 ].clipAt(13); // => 3 [ 1, 2, 3 ].clipAt([ 0, 1, 2, 3 ]); // => [ 1, 2, 3, 3 ]
wrapExtend
but the sequences "clip" (return their last element) rather than wrapping.[ 1, 2, 3 ].clipExtend(9); // => [ 1, 2, 3, 3, 3, 3, 3, 3, 3 ]
put
, but values for index greater than the size of the Array will be clipped to the last index.swap
, but values for index greater than the size of the Array will be clipped to the last index.[1, 2, 3, 4, 5, 6, 7, 8].clump(3); // => [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]
[1, 2, 3, 4, 5, 6, 7, 8].clumps([1, 2]); // => [ [ 1 ], [ 2, 3 ], [ 4 ], [ 5, 6 ], [ 7 ], [ 8 ] ]
[ 1, 2, 3, 4 ].collect("reciprocal"); // => [ 1, 0.5, 0.3333, 0.25 ] (3).collect(function(x) { return x * 100; }); // => [ 0, 100, 200 ]
[1, 2, 3, 4, 5].copyRange(1, 3); // [ 2, 3, 4 ]
[1, 2, 3, 4, 5, 6].copySeries(0, 2, 5); // => [ 1, 3, 5 ]
[1, 2, 3, 4].count("even"); // => 2 [1, 2, 3, 4].count(function(x, i) { return x & i; }); // => 1
(440).cpsmidi(); // => 69 sc.Range("440, 550..880").cpsmidi(); // => [69, 72.8631, 76.0195, 78.6882, 81 ]
(440).cpsoct(); // => 4.75 sc.Range("440, 550..880").cpsoct(); // => [ 4.75, 5.0719, 5.3349, 5.5573, 5.75 ]
[0, 2, 4, 6, 8, 10].curvelin(0, 10, -1, 1); // => [ -1, 0.2222, 0.2905, 0.3846, 0.5375, 1 ]
(12).dbamp(); // => 3.981071705534973 [-6, -3, 0, 3, 6].dbamp(); // => [ 0.5011, 0.7079, 1, 1.412, 1.9952 ]
[1, 2, 3, 4].detect("even"); // => 2 [1, 2, 3, 4].detect(function(x, i) { return x & i; }); // => 3
detect
but returns the index instead of the item itself.[1, 2, 3].difference([2, 3, 4, 5]); // => [ 1 ]
[3, 4, 1, 1].differentiate(); // => [ 3, 1, -3, 0 ]
(1).distort(); // => 0.5 [0, 1, 5, 10].distort(); // => [ 0, 0.5, 0.8333, 0.9090 ]
(10).div(3); // => 3 [10,20,30].div(3); // => [ 3, 6, 10 ]
[1, 2, 3, 4, 5].drop( 3); // [ 4, 5 ] [1, 2, 3, 4, 5].drop(-3); // [ 1, 2 ]
(2).dup(5); // => [ 2, 2, 2, 2, 2 ] [1, 2, 3].dup(3) // => [ [1, 2, 3], [1, 2, 3], [1, 2, 3] ]
Array.exprand(8, 1, 100);
[1, 2, 3, 4].extend(10, 9); // => [ 1, 2, 3, 4, 9, 9, 9, 9, 9, 9 ]
(2000).factors(); // => [ 2, 2, 2, 2, 5, 5, 5 ]
(5).fib(2, 32); // => [ 32, 34, 66, 100, 166 ]
Array.fib(5); // => [ 1, 1, 2, 3, 5 ]
Array.fill(3, 5); // => [ 5, 5, 5 ] Array.fill(3, function(i) { return (i * 2 + 60).midicps(); }); // => [ 440, 493.8833, 554.3652 ]
[1, 2, 3, 4].fill(4); // [ 4, 4, 4, 4 ]
Array.fill2D(3, 3, 1); // => [ [ 1, 1, 1 ], // [ 1, 1, 1 ], // [ 1, 1, 1 ] ]
Array.fill3D(3, 3, 3, 1); // => [ [ [ 1, 1, 1 ],[ 1, 1, 1 ],[ 1, 1, 1 ] ], // [ [ 1, 1, 1 ],[ 1, 1, 1 ],[ 1, 1, 1 ] ], // [ [ 1, 1, 1 ],[ 1, 1, 1 ],[ 1, 1, 1 ] ] ]
Array.fillND([1, 2, 3, 4], function(a, b, c, d) { return a+b+c+d; }); // => 4D
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].find([4, 5, 6]); // => 4
find
but returns an array of all the indices at which the sequence is found.[7, 8, 7, 6, 5, 6, 7, 6, 7, 8, 9].findAll([7, 6]); // => [ 2, 6 ]
[3, 4, 5].first(); // => 3
[[1, 2, 3], [[4, 5], [[6]]]].flat(); // => [ 1, 2, 3, 4, 5, 6 ]
[[1, 2, 3], [[4, 5], [[6]]]].flatten(1); // => [ 1, 2, 3, [ 4, 5 ], [ [ 6 ] ] ] [[1, 2, 3], [[4, 5], [[6]]]].flatten(2); // => [ 1, 2, 3, 4, 5, [ 6 ] ]
[[1, 2, 3], [4, 5, 6]].flop(); // => [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
at
, but values for index greater than the size of the Array will be folded back.[ 1, 2, 3 ].foldAt(5); // => 2 [ 1, 2, 3 ].foldAt([ 0, 1, 2, 3 ]); // => [ 1, 2, 3, 2 ]
wrapExtend
but the sequences fold back on the list elements.[ 1, 2, 3 ].foldExtend(9); // => [ 1, 2, 3, 2, 1, 2, 3, 2, 1 ]
put
, but values for index greater than the size of the Array will be folded back.swap
, but the sequences fold back on the list elements.[3, 6, 9, 12, 15].gcd(100); // => [ 1, 2, 1, 4, 5 ]
Array.geom(5, 1, 3) // => [ 1, 3, 9, 27, 81 ]
(5).geom(1, 3) // => [ 1, 3, 9, 27, 81 ]
[1, 2, 3, 4].includesAll([2, 4]); // => true [1, 2, 3, 4].includesAll([4, 5]); // => false
[1, 2, 3, 4].includesAny([4, 5]); // => true [1, 2, 3, 4].includesAny([5, 6]); // => false
[2, 3, 5, 6].indexIn(5.2); // => 2
blendAt
.[2, 3, 5, 6].indexInBetween(5.2); // => 2.2
[[3], [4], [5]].indexOfEqual([5]); // => 2
[10, 5, 77, 55, 12, 123].indexOfGreaterThan(70); // => 2
[7, 8, 7, 6, 5, 6, 7, 6, 7, 8, 9].indicesOf(7); // => [ 0, 2, 6, 8 ]
indicesOf
, but use equals
method.[[7], [8], [5], [6], 7, 6, [7], 9].indicesOfEqual([7]); // => [ 0, 6 ]
[1, 2, 3, 4, 5].inject(0, "+"); // => 15
[1, 2, 3, 4, 5].injectr([], "++"); // => [ 5, 4, 3, 2, 1 ]
[1, 2, 3, 4].insert(1, 999); // [ 1, 999, 3, 4 ]
Array
with the interpolated values between the start and end values.Array.interpolation(5, 3.2, 20.5); // => [3.2, 7.525, 11.850, 16.175, 20.5]
NaN
.(13).isPrime(); // => true
[1, 2].isSubsetOf([ 1, 2, 3, 4]); // => true [1, 5].isSubsetOf([ 1, 2, 3, 4]); // => false
[1, 2, 3, 4, 5].keep( 3); // => [ 1, 2, 3 ] [1, 2, 3, 4, 5].keep(-3); // => [ 3, 4, 5 ]
l = [0, 1, 5, 9, 11]; // pentatonic scale sc.Range("60..73").collect(function(i) { return i.keyToDegree(l); }); // => [ 25, 26, 26.25, 26.5, 26.75, 27, 27.25, 27.5, 27.75, 28, 28.5, 29, 30, 31 ]
[[1, 2, 3], [0]].lace(10); // => [ 1, 0, 2, 0, 3, 0, 1, 0, 2, 0 ]
[3, 4, 5].last(); // => 5
[3, 6, 12, 24, 48].lcm(20); // => [ 60, 60, 60, 120, 240 ]
(10).linrand();
Array.linrand(8, 1, 100);
[[1, 2, 3], [[41, 52], 5, 6], 1, 2, 3].maxDepth(); // => 3
[3.2, 12.2, 13, 0.4].maxIndex(); // => 2
[ 1, 5, 2, 4, 3 ].maxValue(); // => 5
(69).midicps(); // => 440 sc.Range("69..81").midicps(); // => [ 440, 466.1637, ... , 830.6093, 880 ]
sc.Range("0..12").midiratio(); // => [1, 1.0594, ... , 1.8877, 2]
[3.2, 12.2, 13, 0.4].minIndex(); // => 3
[ -1, -5, -2, -4, -3 ].minValue("abs"); // => -1
[1, 2, 3, 4].mirror(); // => [1, 2, 3, 4, 3, 2, 1]
[1, 2, 3, 4].mirror1(); // => [1, 2, 3, 4, 3, 2]
[1, 2, 3, 4].mirror2(); // => [1, 2, 3, 4, 4, 3, 2, 1]
(10).mod(3); // => 1 [10,20,30].mod(3); // => [ 1, 2, 0 ]
l = [0, 0.5, 0.9, 1]; sc.Range("0, 0.1..1").collect(function(i) { return i.nearestInList(l); }); // => [ 0, 0, 0, 0.5, 0.5, 0.5, 0.5, 0.9, 0.9, 0.9, 1 ]
l = [0, 1, 5, 9, 11]; // pentatonic scale sc.Range("60, 61..76").collect(function(i) { return i.nearestInScale(l, 12); }); // => [ 60, 61, 61, 65, 65, 65, 65, 69, 69, 69, 71, 71, 72, 73, 73, 77, 77 ]
(25).nextPrime(); // => 27
[1, 2, 3].normalize(-20, 10); // => [ -20, -5, 10 ]
this[i] / this.sum()
, so that the array will sum to 1.0.[1, 2, 3].normalizeSum(); // => [ 0.1666, 0.3333, 0.5 ]
[0, 1, 2, 3, 4, 5].nthPrime(); // => [ 2, 3, 5, 7, 11, 13 ]
[1, 2, 3, 3, 4, 3, 4, 3].occurrencesOf(3); // => 4
(10).opAdd(2); // => 12 [10,20,30].sc("+")(10); // => [ 20, 30, 40 ]
(10).opDiv(2); // => 5 [10,20,30].sc("/")(10); // => [ 1, 2, 3 ]
(10).opMod(3); // => 1 [10,20,30].sc("%")(3); // => [ 1, 2, 0 ]
(10).opMul(2); // => 20 [10,20,30].sc("*")(10); // => [ 100, 200, 300 ]
(10).opSub(2); // => 8 [10,20,30].sc("-")(10); // => [ 0, 10, 20 ]
(75).partition(8, 3);
[1, 2, 3].pop(); // 3
(25).prevPrime(); // => 23
[3, 4, 5].putFirst(100); // => [ 100, 4, 5 ] [].putFirst(100); // => []
[3, 4, 5].putLast(100); // => [ 3, 4, 100 ] [].putLast(100); // => []
[1, 2, 3, 4].pyramid(0); // => [ 1, 1, 2, 1, 2, 3, 1, 2, 3, 4 ]
pyramid
, but keep the resulting values grouped in subarrays.[1, 2, 3, 4].pyramidg(0); => [ [ 1 ], [ 1, 2 ], [ 1, 2, 3 ], [ 1, 2, 3, 4 ] ]
sc.Range("0,0.1..1").quantize(1, 0.3, 0.5) // => [ 0, 0.05, 0.1, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 0.95, 1 ]
Array.rand(8, 1, 100);
Array.rand2(8, 100);
sc.Range("1, 1.2..2").ratiomidi(); // => [ 0, 3.1564, 5.8251, 8.1368, 10.1759, 11.9999 ]
[1, 2, 3, 4].resamp0(12); // => [ 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4 ] [1, 2, 3, 4].resamp0( 2); // => [ 1, 4 ]
[1, 2, 3, 4].resamp1(12); // => [ 1, 1.2727, 1.5454, ... , 3.7272, 4 ] [1, 2, 3, 4].resamp1( 3); // => [ 1, 2.5, 4 ]
[1, 2, 3, 4].rotate( 1); // => [ 4, 1, 2, 3 ] [1, 2, 3, 4].rotate(-1); // => [ 2, 3, 4, 1 ]
[1, 2, 3].sect([2, 3, 4, 5]); // => [ 2, 3 ]
sc.Range("0..10").separate("isPrime"); // => [ [0,1,2] , [3], [4,5], [6,7], [8,9,10] ]
Array.series(5, 10, 2); // => [ 10, 12, 14, 16, 18 ]
(5).series(7, 10); // => [ 5, 7, 9 ]
[1, 2, 3, 4, 5, 6].slide(3, 1); // => [ 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6 ]
[1, 2, 3].stutter(2); // => [ 1, 1, 2, 2, 3, 3 ]
sc.Range("0..10").sum(); // => 55
[0,1,2,3,4,5].swap(2, 3); // => [0, 1, 3, 2, 4, 5]
[1, 2, 3].symmetricDifference([2, 3, 4, 5]); // => [ 1, 4, 5 ]
a = [11, 12, 13, 14, 15]; a.take(12); // => 12 a; => [ 11, 15, 13, 14 ]
removeAt
, but does not maintain the order of the items following the one that was removed. Instead, the last item is placed into the position of the removed item and the array's size decreases by one.y = [ 1, 2, 3, 4, 5 ]; y.takeAt(1); // => 2 y; // => [ 1, 5, 3, 4 ]
y = [1, 2, 3, 4]; y.takeThese("odd"); // => [ 4, 2 ] y; // => [ 4, 2 ]
[1, 2, 3].union([2, 3, 4, 5]); // => [ 1, 2, 3, 4, 5 ]
[1, 2, 3, 4].wchoose([0.1, 0.2, 0.3, 0.4]);
at
, but values for index greater than the size of the Array will be wrapped around to 0.[ 1, 2, 3 ].wrapAt(13); // => 2 [ 1, 2, 3 ].wrapAt([ 0, 1, 2, 3 ]); // => [ 1, 2, 3, 1 ]
[ 1, 2, 3 ].wrapExtend(9); // => [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
put
, but values for index greater than the size of the Array will be wrapped around to 0.swap
, but values for index greater than the size of the Array will be wrapped around to 0.p = sc.Pgeom(1, 2, 5); p.next(); // => 1 p.next(); // => 2 p.next(); // => 4 p.next(); // => 8 p.next(); // => 16 p.next(); // => null
p = sc.Prand([1,2,3], 5, 12345); p.next(); // => 3 p.next(); // => 1 p.next(); // => 2 p.next(); // => 1 p.next(); // => 3 p.next(); // => null
p = sc.Pseq([1,2,3], 2); p.next(); // => 1 p.next(); // => 2 p.next(); // => 3 p.next(); // => 1 p.next(); // => 2 p.next(); // => 3 p.next(); // => null
Pseq
, however the repeats variable gives the number of items returned instead of the number of complete cyclesp = sc.Pser([1,2,3], 4); p.next(); // => 1 p.next(); // => 2 p.next(); // => 3 p.next(); // => 1 p.next(); // => null
p = sc.Pseries(0, 2, 5); p.next(); // => 0 p.next(); // => 2 p.next(); // => 4 p.next(); // => 6 p.next(); // => 8 p.next(); // => null
p = sc.Pshuf([1,2,3], 5, 12345); p.next(); // => 2 p.next(); // => 1 p.next(); // => 3 p.next(); // => 2 p.next(); // => 1 p.next(); // => null
r = sc.RGen(100); r.next(); // => 0.6258506774902344 r.next(); // => 0.4134453535079956 r.next(); // => 0.13581514358520508
sc.Range(5); // => [ 0, 1, 2, 3, 4, 5 ] sc.Range("1..5"); // => [ 1, 2, 3, 4, 5 ] sc.Range("5..1"); // => [ 5, 4, 3, 2, 1 ] sc.Range("0, 2.5..10"); // => [ 0, 2.5, 5, 7.5, 10 ] sc.Range("0...10") // => [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
sc.use("global"); // install sc.functions to global namespace midicps(69); // => 40
sc.Scale.major(); // => Major Scale sc.Scale.dorian("Pythagorean"); // => Dorian Scale with Pythagorean Tuning sc.ScaleInfo.names(); // list of scale name sc.ScaleInfo.at("minor"); // => Minor Scale
sc.Scale.choose(7);
sc.Scale.major().degreeToFreq(2, (60).midicps(), 1); // => 659.25511... sc.Scale.major("just").degreeToFreq(2, (60).midicps(), 1); // => 654.06391...
degreeToFreq
, but use blendAt
.sc.Scale.major().degreeToFreq2(2.5, (60).midicps(), 1); // => 678.8557... sc.Scale.major("just").degreeToFreq2(2.5, (60).midicps(), 1); // => 675.8660...
sc.Scale.major().degreeToRatio(2, 1).round(0.001); // => 2.52 sc.Scale.major("just").degreeToRatio(2, 1).round(0.001); // => 2.5
degreeToRatio
, but use blendAt
.sc.Scale.major().degreeToRatio2(2.5, 1).round(0.001); // => 2.595 sc.Scale.major("just").degreeToRatio2(2.5, 1).round(0.001); // => 2.583
sc.Scale.aeolian().pitchesPerOctave(); // 12 sc.Scale.ajam().pitchesPerOctave(); // 24 (this is a quarter-tone scale)
sc.Scale.ionian().size(); // 7 sc.Scale.minorPentatonic().size(); // 5
sc.Scale.major().tuning("just"); // set tuning sc.Scale.major().tuning(); // get tuning
a = sc.Scale.major(); a.wrapAt(4); // => 7 a.wrapAt([5, 6, 7]); // => [ 9, 11, 0 ]
Scale
to generate pitch information.sc.Tuning.et12(); // => equal temperament sc.TuningInfo.names(); // => list of tuning name sc.TuningInfo.at("just"); // => Limit Just Intonation