Conversation
📝 HackYourFuture auto gradeAssignment Score: 0 / 100 ✅Status: ✅ Passed Test Details |
reposman33
left a comment
There was a problem hiding this comment.
Not much to add to this... Just some comments. Kudos!
|
|
||
| // Bonus: Search transactions by date range using slice | ||
| export function searchByDateRange(startDate, endDate) { | ||
| const sorted = [...transactions].sort((a, b) => (a.date > b.date ? 1 : -1)); |
There was a problem hiding this comment.
const sorted = [...transactions].sort((a, b) => a.date - b.date); works the same and is shorter.
MDN says:
A negative value indicates that a should come before b.
A positive value indicates that a should come after b.
so a.date - b.date doesn't have to be -1 or +1, -11 or -4 or 3 is also fine.
|
|
||
| const averages = {}; | ||
| for (const category in categoryTotals) { | ||
| averages[category] = categoryTotals[category] / categoryCounts[category]; |
There was a problem hiding this comment.
With this I get
{
entertainment: 48.88333333333333,
groceries: 93.3875,
healthcare: 128.5,
...
}
with Math.round(categoryTotals[category] / categoryCounts[category]) I get
{
entertainment: 49,
groceries: 93,
healthcare: 129,
...
}
...or use number.toFixed(2)
There was a problem hiding this comment.
really good point,thankssss
| const index = transactions.findIndex(t => t.id === id); | ||
| if (index !== -1) { | ||
| transactions.splice(index, 1); | ||
| return true; |
There was a problem hiding this comment.
// return the new array without the transaction with the given id. Or better, something like transaction with id ${id} removed. 'true' doesn't mean a thing to the person who runs this function.
| const monthTransactions = grouped[month] || []; | ||
| return monthTransactions | ||
| .filter(t => t.type === 'expense') | ||
| .reduce((sum, t) => sum + t.amount, 0); |
| const balance = getBalance(); | ||
| const numTransactions = transactions.length; | ||
| const largestExpenseTransaction = getLargestExpense(); | ||
| const searchDateRange = searchByDateRange('2025-01-15', '2025-01-18'); |
There was a problem hiding this comment.
you use '2025-01-15' and '2025-01-18' @line 236 so:
const startDate = '2025-01-15'
const endDate = '2025-01-18'
const searchDateRange = searchByDateRange(startDate, endDate);
| console.log(streak.join(' → ')); | ||
| }); | ||
|
|
||
| console.log('Transactions from 2025-01-15 to 2025-01-18:'); |
There was a problem hiding this comment.
console.log(`Transactions from ${startDate} to ${endDate}:);
Compelled finance tracker project.