use String.prototype.repeat

This commit is contained in:
Fabian 2022-02-09 16:35:20 +01:00
parent 0acb212956
commit f9bcb08f78
3 changed files with 5 additions and 25 deletions

View file

@ -2,16 +2,9 @@
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)
{
return lines.map(line => repeat(" ", how_much) + line);
return lines.map(line => " ".repeat(how_much) + line);
}
function print_syntax_tree(statements)

View file

@ -47,18 +47,6 @@
}
}
function chr_repeat(chr, count)
{
var result = "";
while(count-- > 0)
{
result += chr;
}
return result;
}
var progress_ticks = 0;
function show_progress(e)
@ -95,12 +83,12 @@
var per50 = Math.floor(per100 / 2);
line += per100 + "% [";
line += chr_repeat("#", per50);
line += chr_repeat(" ", 50 - per50) + "]";
line += "#".repeat(per50);
line += " ".repeat(50 - per50) + "]";
}
else
{
line += chr_repeat(".", progress_ticks++ % 50);
line += ".".repeat(progress_ticks++ % 50);
}
el.textContent = line;

View file

@ -66,8 +66,7 @@ function ScreenAdapter(screen_container, bus)
function number_as_color(n)
{
n = n.toString(16);
return "#" + Array(7 - n.length).join("0") + n;
return "#" + "0".repeat(6 - n.length) + n;
}