Skip to content

Instantly share code, notes, and snippets.

@ericntd
Created August 15, 2020 13:57
Show Gist options
  • Save ericntd/d506334f8cf0261fc9db4ecc14feae8b to your computer and use it in GitHub Desktop.
Save ericntd/d506334f8cf0261fc9db4ecc14feae8b to your computer and use it in GitHub Desktop.
// 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