Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
No if ;) solution in Creative category for [old] Median by Ermin
"use strict";
function median(data) {
data.sort(function (a, b) {return a - b;});
return (data[Math.floor((data.length-1)/2)]+data[Math.ceil((data.length-1)/2)])/2;
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(median([1, 2, 3, 4, 5]), 3, "1st example");
assert.equal(median([3, 1, 2, 5, 3]), 3, "2nd example");
assert.equal(median([1, 300, 2, 200, 1]), 2, "3rd example");
assert.equal(median([3, 6, 20, 99, 10, 15]), 12.5, "4th example");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Sept. 27, 2016
Comments: