Created
October 2, 2018 11:08
-
-
Save tsh-code/fab209d6ab34904e1628af91eb3e9bea 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 sort(values, callback) { | |
return values.slice().sort(callback); | |
} | |
function median(values) { | |
var values = sort(values, function(a,b) {return a - b;} ); | |
var half = Math.floor(values.length/2); | |
if(values.length % 2) | |
return values[half]; | |
else | |
return (values[half-1] + values[half]) / 2.0; | |
} | |
function getLast(values) { | |
return values[values.length - 1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment