Last active
August 7, 2018 13:51
-
-
Save drulabs/e57ed00b25f13b2d768e446d76fdc882 to your computer and use it in GitHub Desktop.
This file contains 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
// THE KOTLIN WAY | |
// 1. Who did maximum number of transactions | |
val maxTransactionsBy = customers.maxBy { it.transactions.count() } | |
// List all transactions irrespective of customers | |
val transactions = customers.flatMap { it.transactions } | |
// 2a. Get total amount deposited in the bank (use transactions constant from above) | |
val totalAmountDeposited = transactions.filter { it.type == "deposit" }.sumByDouble { it.amount } | |
// 2b. Get total amount withdrawn from the bank (use transactions constant from above) | |
val totalAmountWithdrawn = transactions.filter { it.type == "withdraw" }.sumByDouble { it.amount } | |
// 3. What is the net amount deposited? | |
val netAmountDeposited = transactions.fold(0.0) { amount, transaction -> | |
when (transaction.type) { | |
"deposit" -> amount + transaction.amount | |
"withdraw" -> amount - transaction.amount | |
else -> amount | |
} | |
} | |
// 4. The Bank require customers to keep a minimum balance of 1500.00 | |
// Create lists of customers with balance BELOW and ABOVE minimum allowed balance | |
val minimumAllowedLimit = 1500.0 | |
val (lowBalanceCustomers, highBalanceCustomers) = customers.partition { it.balance < minimumAllowedLimit } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment