Created
March 15, 2017 09:37
-
-
Save kgtkr/31fef86d6e549f6473bd1e8b5dc17226 to your computer and use it in GitHub Desktop.
ソート
This file contains 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
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