-
-
Save Atrachtanas/dbcabd3b67604ebeb5415e98334d1a7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ensure the input is an array | |
| if (!Array.isArray(input.transactions)) { | |
| log('Input is not an array'); | |
| return output; | |
| } | |
| // Calculate total amount | |
| let totalAmount = input.transactions.reduce((sum, transaction) => sum + transaction, 0); | |
| // Calculate average transaction value | |
| let averageTransactionValue = totalAmount / input.transactions.length || 0; | |
| // Find the top three highest transactions | |
| let topThreeTransactions = input.transactions | |
| .sort((a, b) => b - a) | |
| .slice(0, 3); | |
| // Assigning computed values to the output properties | |
| output.totalAmount = totalAmount; | |
| output.averageTransactionValue = averageTransactionValue; | |
| output.topThreeTransactions = topThreeTransactions; | |
| // Ensure the results will be passed to the rule output | |
| return output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment