Skip to content

Commit

Permalink
fix bug with wrong length output for every()
Browse files Browse the repository at this point in the history
  • Loading branch information
tmhglnd committed Oct 11, 2023
1 parent 02b5719 commit cd84832
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions build/ts.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build/ts.es5.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/ts.es5.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/transform-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Mod.copy(['c', 'f', 'g'], 3);

## padding

Pad an array with zeroes (or any other value) up to the length specified. The padding value can optionally be changed and the shift argument rotates the list n-steps left or right (negative). This method is similar to `every()` except arguments are not specified in musical bars/divisions.
Pad an array with zeroes (or any other value) up to the length specified. The padding value can optionally be changed and the shift argument rotates the list n-steps left or right (negative). This method is similar to `every()` except arguments are not specified in musical bars/divisions but in array length. A shorter length than input list will slice the output list.

**arguments**
- {NumberArrray} -> Array to use every n-bars
Expand All @@ -133,10 +133,10 @@ Add zeroes to an array with a number sequence. The division determines the amoun

**arguments**
- {NumberArrray} -> Array to use every n-bars
- {Int} -> amount of bars (optional, default=4)
- {Int} -> amount of bars (optional, default=1)
- {Int} -> amount of values per bar (optional, defaul=16)
- {Value} -> padding value for the added items (optional, default=0)
- {Number} -> optional shift in n-divisions (optional, default=0)
- {Number} -> optional shift in n-bars (optional, default=0)

```js
// add zeroes to a rhythm to make it play once over a certain amount of bars
Expand All @@ -148,8 +148,8 @@ Mod.every([3, 0, 7, 9, 11], 2, 8, 12);
//=> [ 3, 0, 7, 9, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12 ]

// change the shift (rotation) with an optional 4th argument
Mod.every([1, 0, 0, 1, 1], 1.5, 8, 0, 0.5);
//=> [ 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ]
Mod.every([1, 0, 0, 1, 1], 2, 8, 0, 1);
//=> [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ]

// works with 2D-array
Mod.every([3, [0, 7, 9], 11], 1, 12);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "total-serialism",
"version": "2.7.1",
"version": "2.7.2",
"description": "A set of methods for the generation and transformation of number sequences useful in algorithmic composition",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ exports.dup = duplicate;
// return {Array}
//
function every(a=[0], bars=1, div=16, pad=0, shift=0){
let len = Math.floor(bars * div) - a.length;
let len = Math.floor(bars * div);
let sft = Math.floor(shift * div);
return padding(a, len, pad, sft);
}
Expand All @@ -106,7 +106,7 @@ exports.every = every;
exports.flatten = flatten;
exports.flat = flatten;

// similar to every(), but instead of specifying bars/devisions
// similar to every(), but instead of specifying bars/divisions
// this method allows you to specify the exact length of the array
// and the shift is not a ratio but in whole integer steps
//
Expand All @@ -122,7 +122,7 @@ function padding(a=[0], length=16, pad=0, shift=0){

let len = length - a.length;
if (len < 1) {
return a;
return a.slice(0, length);
}
let arr = new Array(len).fill(pad);
return rotate(a.concat(arr), shift);
Expand Down
8 changes: 4 additions & 4 deletions test/serialism.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,16 +607,16 @@ function testTransform(){
});

test("Mod.every()", () => {
expect(Mod.every()).toStrictEqual([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]);
expect(Mod.every()).toStrictEqual([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]);
});
test("Mod.every([1, 0, 1, 1, 1], 2, 8)", () => {
expect(Mod.every([1, 0, 1, 1, 1], 2, 8)).toStrictEqual([ 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 ]);
expect(Mod.every([1, 0, 1, 1, 1], 2, 8)).toStrictEqual([ 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]);
});
test("Mod.every([1, 1, 0, 1], 4, 4, 0, -1)", () => {
expect(Mod.every([1, 1, 0, 1], 4, 4, 0, -1)).toStrictEqual([ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1 ]);
expect(Mod.every([1, 1, 0, 1], 4, 4, 0, -1)).toStrictEqual([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1 ]);
});
test("Mod.every([3, [0, 7]], 2, 4, 12)", () => {
expect(Mod.every([3, [0, 7]], 2, 4, 12)).toStrictEqual([ 3, [ 0, 7 ], 12, 12, 12, 12 ]);
expect(Mod.every([3, [0, 7]], 2, 4, 12)).toStrictEqual([ 3, [ 0, 7 ], 12, 12, 12, 12, 12, 12 ]);
});

test("Mod.pad()", () => {
Expand Down

0 comments on commit cd84832

Please sign in to comment.