-
Notifications
You must be signed in to change notification settings - Fork 19
Salem Ba-Rabuod #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
📝 HackYourFuture auto gradeAssignment Score: 0 / 100 ✅Status: ✅ Passed Test Details |
mo92othman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Barboud! Overall, good work 👍
The logic is clear, and the application works as expected. I have left some small comments.
One small setup note: project configuration files (package.json, .gitignore``, Prettier config) are required to be placed inside the project folder itself ( finance-tracker) as the assignments ask for that. Then you needed to create `.gitignore` for `node_modules/`
| export function addTransaction(transaction) { | ||
| if (!transaction[0].id) { | ||
| transaction[0].id = transactions.length + 1; | ||
| } | ||
| transactions.push(...transaction); | ||
| return transactions; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this function expects an array of transactions, but the assignment goal is to add one transaction at a time.
What you wrote is correct, but since the function (by its name) adds a single transaction, we could simplify it to accept one transaction object instead.
| export function getLargestExpense() { | ||
| const filteredTransactions = getTransactionsByType('expense'); | ||
| let largestTransaction = []; | ||
| let largestExpense = null; | ||
| for (const filteredTransaction of filteredTransactions) { | ||
| if (filteredTransaction.amount > largestExpense) { | ||
| largestExpense = filteredTransaction.amount; | ||
| largestTransaction.pop(filteredTransaction); | ||
| largestTransaction.push(filteredTransaction); | ||
| } | ||
| } | ||
| return largestTransaction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of this function is to find one largest expense, but the result is stored inside an array.
But we don't need to store it into an array, because you did that, you needed extra logic (push / pop).
Keeping a single transaction object for the largest expense would be enough. For example:
export function getLargestExpense() {
let largest = null;
for (const transaction of transactions) {
if (transaction.type === 'expense') {
if (largest === null || transaction.amount > largest.amount) {
largest = transaction;
}
}
}
return largest;
}| export function getTotalIncome() { | ||
| let totalIncome = 0; | ||
| for (const transaction of transactions) { | ||
| if (transaction.type === 'income') { | ||
| totalIncome += transaction.amount; | ||
| } | ||
| } | ||
| return totalIncome; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work👍
| addTransaction, | ||
| getTotalIncome, | ||
| getTotalExpenses, | ||
| getBalance, | ||
| getTransactionsByCategory, | ||
| getLargestExpense, | ||
| printAllTransactions, | ||
| printSummary, | ||
| getTransactionsByType, | ||
| getTotalTransactions, | ||
| } from './finance.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small suggestion 🙂
Some imported functions are not used in this file.
It’s best practice to remove unused imports to keep the code clean and easier to read.
No description provided.