use String.prototype.repeat
This commit is contained in:
parent
0acb212956
commit
f9bcb08f78
|
@ -2,16 +2,9 @@
|
||||||
|
|
||||||
const assert = require("assert").strict;
|
const assert = require("assert").strict;
|
||||||
|
|
||||||
function repeat(s, n)
|
|
||||||
{
|
|
||||||
let out = "";
|
|
||||||
for(let i = 0; i < n; i++) out += s;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
function indent(lines, how_much)
|
function indent(lines, how_much)
|
||||||
{
|
{
|
||||||
return lines.map(line => repeat(" ", how_much) + line);
|
return lines.map(line => " ".repeat(how_much) + line);
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_syntax_tree(statements)
|
function print_syntax_tree(statements)
|
||||||
|
|
|
@ -47,18 +47,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function chr_repeat(chr, count)
|
|
||||||
{
|
|
||||||
var result = "";
|
|
||||||
|
|
||||||
while(count-- > 0)
|
|
||||||
{
|
|
||||||
result += chr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var progress_ticks = 0;
|
var progress_ticks = 0;
|
||||||
|
|
||||||
function show_progress(e)
|
function show_progress(e)
|
||||||
|
@ -95,12 +83,12 @@
|
||||||
var per50 = Math.floor(per100 / 2);
|
var per50 = Math.floor(per100 / 2);
|
||||||
|
|
||||||
line += per100 + "% [";
|
line += per100 + "% [";
|
||||||
line += chr_repeat("#", per50);
|
line += "#".repeat(per50);
|
||||||
line += chr_repeat(" ", 50 - per50) + "]";
|
line += " ".repeat(50 - per50) + "]";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
line += chr_repeat(".", progress_ticks++ % 50);
|
line += ".".repeat(progress_ticks++ % 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
el.textContent = line;
|
el.textContent = line;
|
||||||
|
|
|
@ -66,8 +66,7 @@ function ScreenAdapter(screen_container, bus)
|
||||||
function number_as_color(n)
|
function number_as_color(n)
|
||||||
{
|
{
|
||||||
n = n.toString(16);
|
n = n.toString(16);
|
||||||
|
return "#" + "0".repeat(6 - n.length) + n;
|
||||||
return "#" + Array(7 - n.length).join("0") + n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue