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
25 changes: 19 additions & 6 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 transactions.filter(x => x[0] === "income");


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

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

// `calculateTotalIncome` function that:
Expand All @@ -43,8 +45,10 @@ function filterExpenseTransactions(transactions: Transaction[]): Transaction[] {
// calculateTotalIncome(transactions); // => 3200 (1000 + 1500 + 700)
function calculateTotalIncome(transactions: Transaction[]): number {
// write your code here...
const incomeOnly = transactions.filter(x => x[0] === "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?

const totalIncome = incomeOnly.reduce((total,transaction) => total+transaction[1],0);

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

// `calculateTotalExpenses` function that:
Expand All @@ -54,8 +58,10 @@ function calculateTotalIncome(transactions: Transaction[]): number {
// calculateTotalExpenses(transactions); // => 800 (500 + 300)
function calculateTotalExpenses(transactions: Transaction[]): number {
// write your code here...
const expenseOnly = transactions.filter(x => x[0] === "expense");
const totalexpense = expenseOnly.reduce((total,transaction) => total+transaction[1],0);

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

// `calculateNetTotal` function that:
Expand All @@ -65,8 +71,14 @@ function calculateTotalExpenses(transactions: Transaction[]): number {
// calculateNetTotal(transactions); // => 2400 (3200 - 800)
function calculateNetTotal(transactions: Transaction[]): number {
// write your code here...
const incomeOnly = transactions.filter(x => x[0] === "income");
const totalIncome = incomeOnly.reduce((total,transaction) => total+transaction[1],0);

return -1; // replace -1 with what you see is fit
const expenseOnly = transactions.filter(x => x[0] === "expense");
const totalExpense = expenseOnly.reduce((total,transaction) => total+transaction[1],0);


return (totalIncome - totalExpense); // replace -1 with what you see is fit
}

// `filterSignificantTransactions` function that:
Expand All @@ -82,7 +94,8 @@ function filterSignificantTransactions(
): Transaction[] {
// write your code here...

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

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

export {
Expand Down