aboutsummaryrefslogtreecommitdiff
path: root/challenge-251/roger-bell-west/javascript/ch-1.js
blob: 16d97f30e4691ba7994517f767fdcf1edfa8c682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/node

"use strict"

function concat(a0, b0) {
    if (b0 == 0) {
        return 10 * a0;
    }
    let a = a0;
    let b = b0;
    while (b > 0) {
        a *= 10;
        b = Math.floor(b / 10);
    }
    return a + b0;
}

function concatenationvalue(a) {
    let t = 0;
    let ms = Math.floor((a.length - 1) / 2);
    for (let i = 0; i <= ms; i++) {
        const j = a.length - 1 - i;
        if (j == i) {
            t += a[i];
        } else {
            t += concat(a[i], a[j]);
        }
    }
    return t;
}

if (concatenationvalue([6, 12, 25, 1]) == 1286) {
  process.stdout.write("Pass");
} else {
  process.stdout.write("FAIL");
}
process.stdout.write(" ");
if (concatenationvalue([10, 7, 31, 5, 2, 2]) == 489) {
  process.stdout.write("Pass");
} else {
  process.stdout.write("FAIL");
}
process.stdout.write(" ");
if (concatenationvalue([1, 2, 10]) == 112) {
  process.stdout.write("Pass");
} else {
  process.stdout.write("FAIL");
}
process.stdout.write("\n");