Skip to content

Instantly share code, notes, and snippets.

@ericntd
Created August 15, 2020 13:55
Show Gist options
  • Save ericntd/f3f831428369d2d68bb4377836665f47 to your computer and use it in GitHub Desktop.
Save ericntd/f3f831428369d2d68bb4377836665f47 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 departmentTotalSalary = departmentEmployees.sumBy { it.salary }
println("Total salary for department $departmentName is $departmentTotalSalary")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment