Skip to content

Instantly share code, notes, and snippets.

@thetilliwilli
Created May 22, 2019 15:54
Show Gist options
  • Save thetilliwilli/7e4db5c2588bd60a08484b4b9712470f to your computer and use it in GitHub Desktop.
Save thetilliwilli/7e4db5c2588bd60a08484b4b9712470f to your computer and use it in GitHub Desktop.
class CreateOperation {
static OrderBy(getter: (element: any) => any) {
return function (arr: any[]): any[] {
return arr.sort((a, b) => getter(a) - getter(b));
};
}
static OrderByDesc(getter: (element: any) => any) {
return function (arr: any[]): any[] {
return arr.sort((a, b) => getter(b) - getter(a));
};
}
static Last(): any {
return function (arr: any[]): any {
return arr[arr.length - 1];
};
}
static StartFrom(value : any) : Promise<any> {
return Promise.resolve(value);
}
}
var arr = [
{ value: 0 },
{ value: 1 },
{ value: 2 },
];
var result =
CreateOperation
.StartFrom(arr)
.then(CreateOperation.OrderBy(x => x.value))
.then(CreateOperation.Last())
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment