-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (31 loc) · 1.38 KB
/
index.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
#!/usr/bin/env node
// 👆 Used to tell Node.js that this is a CLI tool
"use strict";
import { strategies } from "./strategies.js";
const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
const createPadding = (char, length) =>
Array.from({ length: length }, (_, i) => i + 1)
.map((i) => char)
.join("");
const randomCollectionIndex = random(0, strategies.length - 1);
const selectedStrategyCollection = strategies[randomCollectionIndex];
const randomStrategyIndex = random(
0,
selectedStrategyCollection.strategies.length - 1
);
const selectedStrategy =
selectedStrategyCollection.strategies[randomStrategyIndex];
const credit = `- ${selectedStrategyCollection.name} (${selectedStrategyCollection.year})`;
const contentWidth = Math.max(selectedStrategy.length, credit.length);
const border = createPadding("─", contentWidth);
const padding = createPadding(" ", contentWidth);
const paddedContent = selectedStrategy.padEnd(contentWidth, " ");
const paddedCredit = credit.padStart(contentWidth, " ");
const blockStart = `┌──${border}──┐\n`;
const blank = `│ ${padding} │\n`;
const blockMiddle = `│ ${paddedContent} │\n`;
const blockCredit = `│ ${paddedCredit} │\n`;
const blockEnd = `└──${border}──┘\n`;
const finalOutput =
blockStart + blank + blockMiddle + blank + blockCredit + blank + blockEnd;
console.log(finalOutput);