Skip to content

Commit 142e9af

Browse files
committed
change code style - change some arrow function to a normal function
1 parent b814d3a commit 142e9af

File tree

1 file changed

+88
-77
lines changed

1 file changed

+88
-77
lines changed

src/main.js

Lines changed: 88 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,82 @@ import readlineSync from 'readline-sync'
1111

1212

1313

14-
// Simplify std out from `console.log` into `print`
15-
const print = console.log
16-
17-
1814
/**
1915
* TODO:
2016
*
21-
* - Just complete the program flow based on some print below [0/7]
17+
* - Just complete the program flow based on some print below [2/7]
2218
*/
2319

2420

25-
const DATA_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'data')
21+
// Simplify std out from `console.log` into `print`
22+
const print = console.log;
23+
24+
25+
const DATA_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'data');
26+
27+
28+
/////////////////////////////////////////////////////////////////////
29+
//// 6MMMMb\ MMMMMMMMMM dM. `MMMMMMMb. MMMMMMMMMM /////
30+
//// 6M' ` / MM \ ,MMb MM `Mb / MM \ /////
31+
//// MM MM d'YM. MM MM MM /////
32+
//// YM. MM ,P `Mb MM MM MM /////
33+
//// YMMMMb MM d' YM. MM .M9 MM /////
34+
//// `Mb MM ,P `Mb MMMMMMM9' MM /////
35+
//// MM MM d' YM. MM \M\ MM /////
36+
//// MM MM ,MMMMMMMMb MM \M\ MM /////
37+
//// L ,M9 MM d' YM. MM \M\ MM /////
38+
//// MYMMMM9 _MM_ _dM_ _dMM__MM_ \M\_ _MM_ /////
39+
/////////////////////////////////////////////////////////////////////
40+
41+
(async function() {
42+
do {
43+
console.clear()
44+
print(`
45+
==========================
46+
WELCOME!
47+
==========================
48+
SIMPLE LINEAR REGRESSION DEMO
49+
`)
2650

27-
const showGuide = () => {
51+
const answers = await inquirer.prompt([
52+
{
53+
type: 'list',
54+
name: 'menu',
55+
message: 'Choose menu',
56+
choices: [
57+
'1. Guide',
58+
'2. Run Demo',
59+
'3. Exit'
60+
]
61+
}
62+
])
63+
64+
console.clear()
65+
66+
switch (answers.menu) {
67+
case '1. Guide':
68+
showGuide()
69+
break;
70+
case '2. Run Demo':
71+
await runDemo()
72+
break;
73+
case '3. Exit':
74+
print('Thanks, bye!')
75+
exit(0)
76+
break;
77+
default:
78+
print('Invalid input!')
79+
break;
80+
}
81+
} while (readlineSync.keyInYNStrict(chalk.green('\nContinue program? ')))
82+
})();
83+
84+
85+
86+
87+
88+
89+
function showGuide() {
2890
print('This is a guide for this program!');
2991
for (let i = 1; i <= 5; i++) {
3092
print('Data: ', i)
@@ -36,7 +98,11 @@ const showGuide = () => {
3698
}
3799
}
38100

39-
const runDemo = async () => {
101+
102+
103+
104+
105+
async function runDemo() {
40106
let files
41107
try {
42108
print('Scanning data input file ...')
@@ -61,7 +127,11 @@ const runDemo = async () => {
61127
}
62128
}
63129

64-
const readFileAsync = (filePath) => {
130+
131+
132+
133+
134+
function readFileAsync(filePath) {
65135
return new Promise((resolve, reject) => {
66136
const data = []
67137
fs.createReadStream(filePath)
@@ -83,7 +153,11 @@ const readFileAsync = (filePath) => {
83153
})
84154
}
85155

86-
const previewData = async (filePath) => {
156+
157+
158+
159+
160+
async function previewData(filePath) {
87161
print('\n-----------------------------------------------------\n')
88162
print('Preview data: ', filePath)
89163

@@ -98,9 +172,10 @@ const previewData = async (filePath) => {
98172

99173

100174

101-
const dataIdentification = () => {
175+
function dataIdentification() {
102176
print('\n-----------------------------------------------------\n')
103177
print('Data identification!')
178+
104179
const feature = readlineSync.question('Choose feature: ')
105180
const label = readlineSync.question('Choose label: ')
106181

@@ -112,7 +187,7 @@ const dataIdentification = () => {
112187

113188

114189

115-
const processing = () => {
190+
function processing() {
116191
print('\n-----------------------------------------------------\n')
117192
print('Model processing!')
118193
for (let i = 1; i <= 20; i++) {
@@ -128,7 +203,7 @@ const processing = () => {
128203

129204

130205

131-
const visualization = () => {
206+
function visualization() {
132207
print('\n-----------------------------------------------------\n')
133208
print('Visualization here!')
134209
print('Graph, chart, or whatever...')
@@ -137,67 +212,3 @@ const visualization = () => {
137212
// 7
138213
print('Show the prove of linear equation is actually match with user data')
139214
}
140-
141-
142-
143-
144-
145-
146-
147-
/////////////////////////////////////////////////////////////////////
148-
//// 6MMMMb\ MMMMMMMMMM dM. `MMMMMMMb. MMMMMMMMMM /////
149-
//// 6M' ` / MM \ ,MMb MM `Mb / MM \ /////
150-
//// MM MM d'YM. MM MM MM /////
151-
//// YM. MM ,P `Mb MM MM MM /////
152-
//// YMMMMb MM d' YM. MM .M9 MM /////
153-
//// `Mb MM ,P `Mb MMMMMMM9' MM /////
154-
//// MM MM d' YM. MM \M\ MM /////
155-
//// MM MM ,MMMMMMMMb MM \M\ MM /////
156-
//// L ,M9 MM d' YM. MM \M\ MM /////
157-
//// MYMMMM9 _MM_ _dM_ _dMM__MM_ \M\_ _MM_ /////
158-
/////////////////////////////////////////////////////////////////////
159-
160-
const main = async () => {
161-
do {
162-
console.clear()
163-
print(`
164-
==========================
165-
WELCOME!
166-
==========================
167-
SIMPLE LINEAR REGRESSION DEMO
168-
`)
169-
170-
const answers = await inquirer.prompt([
171-
{
172-
type: 'list',
173-
name: 'menu',
174-
message: 'Choose menu',
175-
choices: [
176-
'1. Guide',
177-
'2. Run Demo',
178-
'3. Exit'
179-
]
180-
}
181-
])
182-
183-
console.clear()
184-
185-
switch (answers.menu) {
186-
case '1. Guide':
187-
showGuide()
188-
break;
189-
case '2. Run Demo':
190-
await runDemo()
191-
break;
192-
case '3. Exit':
193-
print('Thanks, bye!')
194-
exit(0)
195-
break;
196-
default:
197-
print('Invalid input!')
198-
break;
199-
}
200-
} while (readlineSync.keyInYNStrict(chalk.green('\nContinue program? ')))
201-
}
202-
203-
main()

0 commit comments

Comments
 (0)