diff --git a/src/transactions.ts b/src/transactions.ts index f1cd836..6a23516 100644 --- a/src/transactions.ts +++ b/src/transactions.ts @@ -20,10 +20,11 @@ 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[]". @@ -31,20 +32,23 @@ function filterIncomeTransactions(transactions: Transaction[]): Transaction[] { // 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: @@ -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[]". @@ -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 {