Skip to content

Instantly share code, notes, and snippets.

@jzi96
Created October 28, 2015 16:10
Show Gist options
  • Save jzi96/daa9e1053a541cb6aa6b to your computer and use it in GitHub Desktop.
Save jzi96/daa9e1053a541cb6aa6b to your computer and use it in GitHub Desktop.
This is a sortfunction implemented with typescript
function sort<T>(sortItems: T[], key: (item: T) => any): T[]{
var res = sortItems.slice(0);
res.sort(function (a, b) {
var akey = key(a);
var bkey = key(b);
return akey > bkey ? 1 : akey < bkey ? -1 : 0;
});
return res;
}
var t = [
{name:"my", price: 5.0}, {name:"test", price:56.6},
];
sort(t, x=> x.name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment