Created
March 29, 2017 20:24
-
-
Save mrmlnc/6080c2ed183a8d1dbf8ee28c890d7d69 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 median3(a: number, b: number, c: number): number { | |
if ((a - b) * (c - a) >= 0) { | |
return a; | |
} else if ((b - a) * (c - b) >= 0) { | |
return b; | |
} | |
return c; | |
} | |
console.log(2 === median3(1, 2, 3)); | |
console.log(2 === median3(1, 3, 2)); | |
console.log(2 === median3(3, 2, 1)); | |
console.log(2 === median3(3, 1, 2)); | |
console.log(2 === median3(2, 1, 3)); | |
console.log(2 === median3(2, 3, 1)); | |
console.log(2 === median3(1, 2, 2)); | |
console.log(2 === median3(2, 1, 2)); | |
console.log(2 === median3(2, 2, 1)); | |
console.log(2 === median3(2, 2, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment