Skip to content

Instantly share code, notes, and snippets.

@kgtkr
Created March 15, 2017 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgtkr/31fef86d6e549f6473bd1e8b5dc17226 to your computer and use it in GitHub Desktop.
Save kgtkr/31fef86d6e549f6473bd1e8b5dc17226 to your computer and use it in GitHub Desktop.
ソート
function compareTo(calls: (() => number)[]): number {
for (let call of calls) {
let i = call();
if (i!==0) {
return i;
}
}
return 0;
}
class Hoge {
a: number;
b: number;
c: number;
d: number;
compareTo(that: Hoge): number {
return compareTo([
() => {
if(this.a<that.a){
return 1;
}else if(this.a>that.a){
return -1;
}else{
return 0;
}
},
() => {
if(this.b<that.b){
return 1;
}else if(this.b>that.b){
return -1;
}else{
return 0;
}
},
() => {
if(this.c<that.c){
return 1;
}else if(this.c>that.c){
return -1;
}else{
return 0;
}
},
() => {
if(this.d<that.d){
return 1;
}else if(this.d>that.d){
return -1;
}else{
return 0;
}
}
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment