From e0dc63599d65be0484d0ddc94a828186b41aced4 Mon Sep 17 00:00:00 2001 From: maobaid Date: Mon, 10 Mar 2025 13:33:33 +0300 Subject: [PATCH 1/2] Done --- src/transactions.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/transactions.ts b/src/transactions.ts index f1cd836..f71899b 100644 --- a/src/transactions.ts +++ b/src/transactions.ts @@ -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((n) => n[0] == "income"); // replace empty array with what you see is fit } // `filterExpenseTransactions` function that: @@ -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((n) => n[0] == "expense"); // replace empty array with what you see is fit } // `calculateTotalIncome` function that: @@ -44,7 +44,9 @@ function filterExpenseTransactions(transactions: Transaction[]): Transaction[] { function calculateTotalIncome(transactions: Transaction[]): number { // write your code here... - return -1; // replace -1 with what you see is fit + return transactions + .filter((n) => n[0] == "income") + .reduce((total, n) => total + n[1], 0); // replace -1 with what you see is fit } // `calculateTotalExpenses` function that: @@ -55,7 +57,9 @@ function calculateTotalIncome(transactions: Transaction[]): number { function calculateTotalExpenses(transactions: Transaction[]): number { // write your code here... - return -1; // replace -1 with what you see is fit + return transactions + .filter((n) => n[0] == "expense") + .reduce((total, n) => total + n[1], 0); // replace -1 with what you see is fit } // `calculateNetTotal` function that: @@ -66,7 +70,9 @@ function calculateTotalExpenses(transactions: Transaction[]): number { function calculateNetTotal(transactions: Transaction[]): number { // write your code here... - return -1; // replace -1 with what you see is fit + return ( + calculateTotalIncome(transactions) - calculateTotalExpenses(transactions) + ); // replace -1 with what you see is fit } // `filterSignificantTransactions` function that: @@ -82,7 +88,7 @@ function filterSignificantTransactions( ): Transaction[] { // write your code here... - return []; // replace empty array with what you see is fit + return transactions.filter((n) => n[1] >= 1000); // replace empty array with what you see is fit } export { From 853522d9ec311b0b40ce2dd95a894594a74a1dbd Mon Sep 17 00:00:00 2001 From: maobaid Date: Mon, 10 Mar 2025 15:54:24 +0300 Subject: [PATCH 2/2] Fixed threshold on last task --- src/transactions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transactions.ts b/src/transactions.ts index f71899b..8e8b4f0 100644 --- a/src/transactions.ts +++ b/src/transactions.ts @@ -88,7 +88,7 @@ function filterSignificantTransactions( ): Transaction[] { // write your code here... - return transactions.filter((n) => n[1] >= 1000); // replace empty array with what you see is fit + return transactions.filter((n) => n[1] >= threshold); // replace empty array with what you see is fit } export {