Created
October 29, 2017 05:17
-
-
Save rogerpoon/f4afbe455956b638b53f839de2502560 to your computer and use it in GitHub Desktop.
JS++ Custom Sorting
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
import System; | |
class Employee : IComparable<Employee> | |
{ | |
private string firstName; | |
private string lastName; | |
public Employee(string firstName, string lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
public Comparison compare(Employee that) { | |
// Sort by employee surname | |
return this.lastName.compare(that.lastName); | |
} | |
public override string toString() { | |
return this.firstName + " " + this.lastName; | |
} | |
} | |
Employee zig = new Employee("Zig", "Ziglar"); | |
Employee john = new Employee("John", "Smith"); | |
Employee abe = new Employee("Abe", "Lincoln"); | |
Employee[] employees = [ zig, john, abe ]; | |
employees.sort(); | |
Console.log(employees.join(", ")); | |
// Output: | |
// Abe Lincoln, John Smith, Zig Ziglar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment