Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Created October 2, 2018 11:08
Show Gist options
  • Save tsh-code/fab209d6ab34904e1628af91eb3e9bea to your computer and use it in GitHub Desktop.
Save tsh-code/fab209d6ab34904e1628af91eb3e9bea to your computer and use it in GitHub Desktop.
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