devicescript
devicescript copied to clipboard
string concatenation is qudratic
This should run reasonably fast, but doesn't.
let s = ""
for (let i = 0; i < 2000; ++i) {
s += "x"
}
ds.assert(s.length == 2000 && s[100] == "x")
Note that Array.join is implemented, so the recommended way of doing the above is:
let sa: string[] = []
for (let i = 0; i < 2000; ++i) {
sa.push("x")
}
const s = sa.join("")
ds.assert(s.length == 2000 && s[100] == "x")