-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (69 loc) · 2.65 KB
/
index.js
File metadata and controls
80 lines (69 loc) · 2.65 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Importing necessary functions and modules
import filterData from "./src/filters.js";
import parseCsv from "./src/parseCsv.js";
import { promptForChoice, enterValues, promptForYesOrNo, promptForBudget } from "./src/cmd.js";
// Main function to execute the program
const main = async () => {
// Parsing the CSV file to get car data
const cars = await parseCsv("./data/cars.csv");
// Prompting user for choice
const choice = await promptForChoice();
// Handling user's choice
if (choice === "1") {
// If user chooses option 1, prompt for filter values
const filters = await enterValues();
// Filtering cars based on user's filters
const data = filterData(cars, filters);
// If no cars match the filter, display message and exit
if (data.length === 0) {
console.log("No vehicle matches your filter");
process.exit(0);
}
// Prompting user to display filtered data
const shouldDisplayData = await promptForYesOrNo();
// Displaying filtered data if requested by user
if (shouldDisplayData) {
console.log("Filtered data:", JSON.stringify(data, null, 2));
} else {
// Displaying message if user cancels
console.log("User cancelled. Exiting...");
}
// Exiting the program
process.exit(0);
}
if (choice === "2") {
const budgetForExpensive = await promptForBudget("Enter the budget for expensive vehicles:");
const expensiveVehicles = cars.filter(car => car.selling_price > budgetForExpensive);
if (expensiveVehicles.length === 0) {
console.log("No vehicle matches your filter");
process.exit(0);
}
const shouldDisplayExpensive = await promptForYesOrNo();
if (shouldDisplayExpensive) {
console.log("Expensive vehicles:", JSON.stringify(expensiveVehicles, null, 2));
} else {
console.log("User cancelled. Exiting...");
}
process.exit(0);
}
if (choice === "3") {
const budgetForInexpensive = await promptForBudget("Enter the budget for inexpensive vehicles:");
const inexpensiveVehicles = cars.filter(car => car.selling_price < budgetForInexpensive);
if (inexpensiveVehicles.length === 0) {
console.log("No vehicle matches your filter");
process.exit(0);
}
const shouldDisplayInexpensive = await promptForYesOrNo();
if (shouldDisplayInexpensive) {
console.log("Inexpensive vehicles:", JSON.stringify(inexpensiveVehicles, null, 2));
} else {
console.log("User cancelled. Exiting...");
}
process.exit(0);
}
// Displaying message for invalid choice
console.log("Invalid choice.");
process.exit(1);
};
// Calling the main function to start the program
main();