aboutsummaryrefslogtreecommitdiff
path: root/challenge-252/zapwai/javascript/ch-1.js
blob: 8b95a0d51c1334332f3d6276067a52917b8ee0f1 (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
let ints = [1, 2, 3, 4];
let ints2 = [2, 7, 1, 19, 18, 3];

proc(ints);
proc(ints2);

function total( list ) {
    let sum = 0;
    for (let i of list) {
	sum += i*i;
    }
    return sum;
}

function proc( ints ) {
    let n = ints.length;
    let spec = [];
    for (let i = 0; i < n; i++) {
	if (n % (i + 1) == 0) {
	    spec.push(ints[i]);
	}
    }
    console.log("Input:", ints);
    console.log("Output:", total( spec ));
}