Skip to content
Open
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
33 changes: 21 additions & 12 deletions src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ const transactions: Transaction[] = [
// filterIncomeTransactions(transactions); // => [["income", 1000], ["income", 1500], ["income", 700]]
function filterIncomeTransactions(transactions: Transaction[]): Transaction[] {
// write your code here...

return []; // replace empty array with what you see is fit
const incomeTrans: Transaction[] = transactions.filter((n) =>
n.includes("income")
);
return incomeTrans; // replace empty array with what you see is fit
}

// `filterExpenseTransactions` function that:
Expand All @@ -32,8 +34,10 @@ function filterIncomeTransactions(transactions: Transaction[]): Transaction[] {
// filterExpenseTransactions(transactions); // => [["expense", 500], ["expense", 300]]
function filterExpenseTransactions(transactions: Transaction[]): Transaction[] {
// write your code here...

return []; // replace empty array with what you see is fit
const expenseTrans: Transaction[] = transactions.filter((n) =>
n.includes("expense")
);
return expenseTrans; // replace empty array with what you see is fit
}

// `calculateTotalIncome` function that:
Expand All @@ -43,8 +47,10 @@ 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
const total = transactions
.filter((n) => n.includes("income"))

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((t, n) => t + n[1], 0);
return total; // replace -1 with what you see is fit
}

// `calculateTotalExpenses` function that:
Expand All @@ -54,8 +60,10 @@ 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
const total = transactions
.filter((n) => n.includes("expense"))
.reduce((t, n) => t + n[1], 0);
return total; // replace -1 with what you see is fit
}

// `calculateNetTotal` function that:
Expand All @@ -65,8 +73,9 @@ function calculateTotalExpenses(transactions: Transaction[]): number {
// calculateNetTotal(transactions); // => 2400 (3200 - 800)
function calculateNetTotal(transactions: Transaction[]): number {
// write your code here...

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

// `filterSignificantTransactions` function that:
Expand All @@ -81,8 +90,8 @@ function filterSignificantTransactions(
threshold: number
): Transaction[] {
// write your code here...

return []; // replace empty array with what you see is fit
const thingy = transactions.filter((n) => n[1] >= threshold);
return thingy; // replace empty array with what you see is fit
}

export {
Expand Down