Top rank per group: Difference between revisions
Content added Content deleted
m (→{{header|EchoLisp}}: deleted excess </lang>) |
|||
Line 1,247: | Line 1,247: | ||
<lang dyalect>type Employee(name,id,salary,department) |
<lang dyalect>type Employee(name,id,salary,department) |
||
func Employee. |
func Employee.ToString() { |
||
"$\(this |
"$\(this.salary) (name: \(this.name), id: \(this.id), department: \(this.department)" |
||
} |
} |
||
Line 1,269: | Line 1,269: | ||
func topNSalaries(n) { |
func topNSalaries(n) { |
||
//We sort employees based on salary |
//We sort employees based on salary |
||
employees. |
employees.Sort(by: (x,y) => y.salary - x.salary) |
||
let max = |
let max = |
||
if n > employees. |
if n > employees.Length() - 1 { |
||
employees. |
employees.Length() - 1 |
||
} else { |
} else { |
||
n |
n |