Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 14 additions & 11 deletions src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const transactions: Transaction[] = [
function filterIncomeTransactions(transactions: Transaction[]): Transaction[] {
// write your code here...

return []; // replace empty array with what you see is fit
return transactions.filter(([type]) => type === "income");
// replace empty array with what you see is fit
}

// `filterExpenseTransactions` function that:
Expand All @@ -33,7 +34,7 @@ function filterIncomeTransactions(transactions: Transaction[]): Transaction[] {
function filterExpenseTransactions(transactions: Transaction[]): Transaction[] {
// write your code here...

return []; // replace empty array with what you see is fit
return transactions.filter(([type]) => type === "expense"); // replace empty array with what you see is fit
}

// `calculateTotalIncome` function that:
Expand All @@ -43,8 +44,9 @@ function filterExpenseTransactions(transactions: Transaction[]): Transaction[] {
// calculateTotalIncome(transactions); // => 3200 (1000 + 1500 + 700)
function calculateTotalIncome(transactions: Transaction[]): number {
// write your code here...

return -1; // replace -1 with what you see is fit
return transactions
.filter(([type]) => type === "income")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not reuse the functions you already defined?

.reduce((sum, [, amount]) => sum + amount, 0); // replace -1 with what you see is fit
}

// `calculateTotalExpenses` function that:
Expand All @@ -54,8 +56,9 @@ function calculateTotalIncome(transactions: Transaction[]): number {
// calculateTotalExpenses(transactions); // => 800 (500 + 300)
function calculateTotalExpenses(transactions: Transaction[]): number {
// write your code here...

return -1; // replace -1 with what you see is fit
return transactions
.filter(([type]) => type === "expense")
.reduce((sum, [, amount]) => sum + amount, 0); // replace -1 with what you see is fit
}

// `calculateNetTotal` function that:
Expand All @@ -66,7 +69,9 @@ function calculateTotalExpenses(transactions: Transaction[]): number {
function calculateNetTotal(transactions: Transaction[]): number {
// write your code here...

return -1; // replace -1 with what you see is fit
return (
calculateTotalIncome(transactions) - calculateTotalExpenses(transactions)
); // replace -1 with what you see is fit
}

// `filterSignificantTransactions` function that:
Expand All @@ -80,9 +85,7 @@ function filterSignificantTransactions(
transactions: Transaction[],
threshold: number
): Transaction[] {
// write your code here...

return []; // replace empty array with what you see is fit
return transactions.filter(([, amount]) => amount >= threshold); // replace empty array with what you see is fit
}

export {
Expand All @@ -93,4 +96,4 @@ export {
calculateTotalExpenses,
calculateNetTotal,
filterSignificantTransactions,
};
};