Tim Van Wassenhove

Passionate geek, interested in Technology. Proud father of two

28 Jul 2014

Cute sort implementation

For years I had been implementing my sort functions as following:

(x,y) => {  
	if (x.PartName == null && y.PartName == null) return 0;
	if (x.PartName == null) return -1;
	if (y.PartName == null) return 1; 
	return x.PartName.CompareTo(y.PartName);
}

Earlier today I found the following cute variant while browsing through the ServiceStack codebase:

(x,y) => x.Priority - y.Priority