string(): make zero padding work if arg is 0
This commit is contained in:
parent
601f1c14c4
commit
bab238d58b
1 changed files with 1 additions and 3 deletions
|
@ -29,9 +29,7 @@ var switch = func(n, b, v) n - (test(n, b) - !!v) * bit[b];
|
||||||
# returns number <n> as bit string, zero-padded to <len> digits:
|
# returns number <n> as bit string, zero-padded to <len> digits:
|
||||||
# bits.string(6) -> "110"
|
# bits.string(6) -> "110"
|
||||||
# bits.string(6, 8) -> "00000110"
|
# bits.string(6, 8) -> "00000110"
|
||||||
var string = func(n, len = 0) {
|
var string = func(n, len = 1) {
|
||||||
if (!n)
|
|
||||||
return '0';
|
|
||||||
var s = "";
|
var s = "";
|
||||||
while (n) {
|
while (n) {
|
||||||
var v = int(n / 2);
|
var v = int(n / 2);
|
||||||
|
|
Loading…
Reference in a new issue