Skip to content

Instantly share code, notes, and snippets.

@Atrachtanas
Created May 29, 2024 14:03
Show Gist options
  • Select an option

  • Save Atrachtanas/dbcabd3b67604ebeb5415e98334d1a7c to your computer and use it in GitHub Desktop.

Select an option

Save Atrachtanas/dbcabd3b67604ebeb5415e98334d1a7c to your computer and use it in GitHub Desktop.
// 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