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

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

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

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

// `calculateTotalIncome` function that:
Expand All @@ -43,8 +49,11 @@ function filterExpenseTransactions(transactions: Transaction[]): Transaction[] {
// calculateTotalIncome(transactions); // => 3200 (1000 + 1500 + 700)
function calculateTotalIncome(transactions: Transaction[]): number {
// write your code here...
const totalIncome = transactions
.filter((transaction) => transaction[0] === "income")
.reduce((sum, transaction) => sum + transaction[1], 0);

return -1; // replace -1 with what you see is fit
return totalIncome; // return the calculated total income
}

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

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

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

return -1; // replace -1 with what you see is fit
return totalomaines; // return the calculated net total
}

// `filterSignificantTransactions` function that:
Expand All @@ -80,9 +94,18 @@ function filterSignificantTransactions(
transactions: Transaction[],
threshold: number
): Transaction[] {
return transactions.filter(([type, amount]) => amount >= threshold);



const result = filterSignificantTransactions(transactions, 1000);
console.log(result);
// Output: [["income", 1000], ["income", 1500], ["expense", 2000]]


// write your code here...

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

export {
Expand Down