Fine... (as I seem to be wasting my time anyway)
1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
29
3031
32
33
34
3536
37
38
39
4041
42
43
44
4546
47
48
49
50 |
function inc(n)
{
return n + 1;
}
function add(a, b)
{
var carry = 0;
var r = [];
for (var i = 0; i < Math.max(a.length, b.length); i++)
{
var tmp = carry;
if (i < a.length) {
tmp += a[i];
}
if (i < b.length)
{ tmp += b[i];
}
carry = Math.floor(tmp / 10);
r.push(tmp % 10);
}
if (carry !== 0)
{
r.push(carry);
}
return r;
}
function f(n){
var l = [];
var r = [0];
for (var i=1; i<=n; i++) {
l = l.map(inc);
l.push(i);
var s = l.join("").split("").map(Number).reverse();
r = add(r, s); }
return r.reverse().join("");
}
|
Hopefully someone who does use JS can show why this is awful. Until then I'll take it as a confirmation that JS is awful.