base now accepts Arrays which improve compatibility with rockstar-strudel
This commit is contained in:
parent
bd68c6a0a7
commit
475f17ddfd
1 changed files with 10 additions and 8 deletions
|
|
@ -4135,7 +4135,7 @@ export const worklet = (...args) => pure({}).worklet(...args);
|
||||||
*
|
*
|
||||||
* @name base
|
* @name base
|
||||||
* @tags generators
|
* @tags generators
|
||||||
* @param {number} n - number to convert (can be a pattern)
|
* @param {number} n - number to convert (can be a pattern or array)
|
||||||
* @param {number} b - base to convert to (defaults to 10) (can be a pattern)
|
* @param {number} b - base to convert to (defaults to 10) (can be a pattern)
|
||||||
* @param {number} d - max number of digits to produce for each n (defaults to 0 for all) (can be a pattern)
|
* @param {number} d - max number of digits to produce for each n (defaults to 0 for all) (can be a pattern)
|
||||||
* @example
|
* @example
|
||||||
|
|
@ -4143,13 +4143,15 @@ export const worklet = (...args) => pure({}).worklet(...args);
|
||||||
* // $: note("1 7 5 5 4 3").scale("c:major").s("saw")
|
* // $: note("1 7 5 5 4 3").scale("c:major").s("saw")
|
||||||
*/
|
*/
|
||||||
export const base = (n, b = 10, d=0) => {
|
export const base = (n, b = 10, d=0) => {
|
||||||
|
if(Array.isArray(n)){
|
||||||
|
n = sequence(n);
|
||||||
|
}
|
||||||
n = reify(n);
|
n = reify(n);
|
||||||
b = reify(b);
|
b = reify(b);
|
||||||
d = reify(d);
|
d = reify(d);
|
||||||
|
|
||||||
return d.withValue(e => {
|
return d.withValue(e => {
|
||||||
return b.withValue(c => {
|
return b.withValue(c => {
|
||||||
//console.log("base", n, c)
|
|
||||||
return n.withValue(v => {
|
return n.withValue(v => {
|
||||||
let digits = [];
|
let digits = [];
|
||||||
let value = v;
|
let value = v;
|
||||||
|
|
@ -4158,21 +4160,21 @@ export const base = (n, b = 10, d=0) => {
|
||||||
value = Math.floor(value / c);
|
value = Math.floor(value / c);
|
||||||
}
|
}
|
||||||
if (e){
|
if (e){
|
||||||
const l = digits.length
|
const l = digits.length;
|
||||||
if (l > e){
|
if (l > e){
|
||||||
digits = digits.slice(-1 * e)
|
digits = digits.slice(-1 * e);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if (l < e){
|
if (l < e){
|
||||||
for (let i = l; i < e; i++) {
|
for (let i = l; i < e; i++) {
|
||||||
digits.unshift("~");//0); //Would like to be padding this but ~- doesn't work
|
digits.unshift("~");//0); //Would like to be padding this but ~- doesn't work
|
||||||
}
|
}
|
||||||
console.log("digits", digits)
|
console.log("digits", digits);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
return sequence(digits);
|
return sequence(digits);
|
||||||
}).squeezeJoin()
|
}).squeezeJoin();
|
||||||
}).squeezeJoin()
|
}).squeezeJoin();
|
||||||
}).squeezeJoin()
|
}).squeezeJoin();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue