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
32 changes: 23 additions & 9 deletions src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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((trans) => trans.includes("income")); // replace empty array with what you see is fit
}

// `filterExpenseTransactions` function that:
Expand All @@ -33,7 +33,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((trans) => trans.includes("expense")); // replace empty array with what you see is fit
}

// `calculateTotalIncome` function that:
Expand All @@ -43,8 +43,12 @@ 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
let IncomeTrans: Transaction[] = filterIncomeTransactions(transactions);

Choose a reason for hiding this comment

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

variable names should start with small letter to avoid confusing them with Types

let sum = IncomeTrans? IncomeTrans.reduce((x, trans) => {
return x + trans[1];
}, 0)
: 0;
return sum; // replace -1 with what you see is fit
}

// `calculateTotalExpenses` function that:
Expand All @@ -54,8 +58,12 @@ 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
let ExpTrans: Transaction[] = filterExpenseTransactions(transactions);
let sum = ExpTrans? ExpTrans.reduce((x, trans) => {
return x + trans[1];
}, 0)
: 0;
return sum; // 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
return calculateTotalIncome(transactions) - calculateTotalExpenses(transactions);

// return total; // replace -1 with what you see is fit
}

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

let transFiltered: Transaction[] = transactions.filter((trans) => trans[1] >= threshold);
return transFiltered;

return []; // replace empty array with what you see is fit
// return []; // replace empty array with what you see is fit
}



export {
Transaction,
filterIncomeTransactions,
Expand Down