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
45 changes: 29 additions & 16 deletions src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,35 @@ const transactions: Transaction[] = [
// example:
// filterIncomeTransactions(transactions); // => [["income", 1000], ["income", 1500], ["income", 700]]
function filterIncomeTransactions(transactions: Transaction[]): Transaction[] {
// write your code here...
let onI = transactions.filter((a) => a.includes("income"));

return []; // replace empty array with what you see is fit
return onI; // replace empty array with what you see is fit
}
console.log(filterIncomeTransactions(transactions));

// `filterExpenseTransactions` function that:
// - Accepts a "transactions" parameter of type "Transaction[]".
// - Return a new array containing only the expense transactions.
// example:
// filterExpenseTransactions(transactions); // => [["expense", 500], ["expense", 300]]
function filterExpenseTransactions(transactions: Transaction[]): Transaction[] {
// write your code here...
let onE = transactions.filter((b) => b.includes("expense"));

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

console.log(filterExpenseTransactions(transactions));
// `calculateTotalIncome` function that:
// - Accepts a "transactions" parameter of type "Transaction[]".
// - calculates the total income and returns it.
// example:
// calculateTotalIncome(transactions); // => 3200 (1000 + 1500 + 700)
function calculateTotalIncome(transactions: Transaction[]): number {
// write your code here...
let calI = transactions
.filter((c) => c.includes("income"))
.map((c) => 1)
.reduce((sum, amount) => sum + amount, 0);

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

// `calculateTotalExpenses` function that:
Expand All @@ -53,22 +57,33 @@ function calculateTotalIncome(transactions: Transaction[]): number {
// example:
// calculateTotalExpenses(transactions); // => 800 (500 + 300)
function calculateTotalExpenses(transactions: Transaction[]): number {
// write your code here...
let calcE = transactions
.filter((d) => d.includes("expense"))
.map((d) => 1)
.reduce((sum, amount) => sum + amount, 0);

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

console.log(calculateTotalExpenses(transactions));
// `calculateNetTotal` function that:
// - Accepts a "transactions" parameter of type "Transaction[]".
// - calculates the net total (total income - total expenses) and returns it.
// example:
// calculateNetTotal(transactions); // => 2400 (3200 - 800)
function calculateNetTotal(transactions: Transaction[]): number {
// write your code here...
let neti = transactions
.filter((n) => n.includes("income"))
.map((n) => 1)
.reduce((sum, amount) => sum + amount, 0);
let nete = transactions
.filter((ne) => ne.includes("expense"))
.map((ne) => 1)
.reduce((sum, amount) => sum + amount, 0);
let netTotal = neti + nete;

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

console.log(calculateNetTotal(transactions));
// `filterSignificantTransactions` function that:
// - Accepts 2 parameters:
// - a "transactions" parameter of type "Transaction[]".
Expand All @@ -80,9 +95,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((k) => k[1] >= threshold); // replace empty array with what you see is fit
}

export {
Expand Down
Loading