-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquestion9.js
38 lines (28 loc) · 857 Bytes
/
question9.js
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
/**
*
Write a function that takes a list of strings an prints them, one per line, in a rectangular frame. For example the list ["Hello", "World", "in", "a", "frame"] gets printed as:
*********
* Hello *
* World *
* in *
* a *
* frame *
*********
*
*/
const myWords = ["hanumansingh", "Hello", "World", "in", "a", "rame", "boy"];
let lenghts = [];
for (let i = 0; i <= myWords.length - 1; i++) {
lenghts.push(myWords[i].length);
}
const biggestLenght = lenghts.sort(function (a, b) {
return a - b;
})[lenghts.length - 1];
console.log(biggestLenght);
console.log("*".repeat(biggestLenght + 4));
for (let i = 0; i <= myWords.length - 1; i++) {
let lengthDiffrence = biggestLenght - myWords[i].length;
let word = myWords[i];
console.log(`* ${word} ${" ".repeat(lengthDiffrence)}*`);
}
console.log("*".repeat(biggestLenght + 4));