Created
May 22, 2019 15:54
-
-
Save thetilliwilli/7e4db5c2588bd60a08484b4b9712470f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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