function median( arr ) {
	var len = arr.length;
	var id;
	var d;
	var i;

	if ( !len ) {
		return null;
	}

	// Copy and sort data in ascending order:
	d = [];
	for ( i = 0; i < len; i++ ) {
		d.push( arr[ i ] );
	}
	d.sort( ascending );

	// Get the middle index:
	id = floor( len / 2 );

	if ( len % 2 ) {
		// The number of elements is not evenly divisible by two, hence we have a middle index:
		return d[ id ];
	}
	// Even number of elements, so must take the mean of the two middle values:
	return ( d[ id-1 ] + d[ id ] ) / 2.0;
}
Computes the median of an array.

@param {Array} arr - input array
@returns {number} median value