Created
August 15, 2020 13:57
-
-
Save ericntd/d506334f8cf0261fc9db4ecc14feae8b 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
// prepare variable employees which is a list of Employee object | |
// Same as Task 0 | |
employees.groupBy { it.department } | |
.map { group -> | |
val departmentName = group.key | |
val departmentEmployees = group.value | |
val departmentAverageSalary = departmentEmployees.sumBy { it.salary } / departmentEmployees.size | |
println("Average salary for department $departmentName is $departmentAverageSalary") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment