blob: e2f7dfaa4603caa8564a0e6f0159bd6d80dbc5a9 (
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
|
function center(words) {
let lens = [];
for (let word of words)
lens.push(word.length);
let m = max(lens);
let ind = 0;
for (let l of lens) {
let sp = (m - l) / 2;
let s = "";
for (let i = 0; i < sp; i++)
s += " ";
s += words[ind] + "<br>";
ind++;
document.write(s);
}
}
function max (nums) {
let max = 0;
for (let n of nums) {
if (max < n)
max = n;
}
return max;
}
let words = ["This", "is", "a test of the", "center function"];
center(words);
console.log(max([3, 5, 7, 1, 15]));
|