src/analysis.js
function bucketNumbersLinearly(data, bucketCount, min, max) {
    var i = 0,
        l = data.length;
    // If min and max aren't given, set them to the highest and lowest data values
    if (typeof min === 'undefined') {
        min = Infinity;
        max = -Infinity;
        for (i = 0; i < l; i++) {
            if (data[i] < min) min = data[i];
            if (data[i] > max) max = data[i];
        }
    }
    var inc = (max - min) / bucketCount,
        buckets = new Array(bucketCount);
    // Initialize buckets
    for (i = 0; i < bucketCount; i++) {
        buckets[i] = [];
    }
    // Put the numbers into buckets
    for (i = 0; i < l; i++) {
        // Buckets include the lower bound but not the higher bound, except the top bucket
        try {
            if (data[i] === max) buckets[bucketCount-1].push(data[i]);
            else buckets[((data[i] - min) / inc) | 0].push(data[i]);
        } catch(e) {
            console.warn('Numbers in the data are outside of the min and max values used to bucket the data.');
        }
    }
    return buckets;
}
function bucketNumbersLinearly(data, bucketCount, min, max) {
    var i = 0,
        l = data.length;
    // If min and max aren't given, set them to the highest and lowest data values
    if (typeof min === 'undefined') {
        min = Infinity;
        max = -Infinity;
        for (i = 0; i < l; i++) {
            if (data[i] < min) min = data[i];
            if (data[i] > max) max = data[i];
        }
    }
    var inc = (max - min) / bucketCount,
        buckets = new Array(bucketCount);
    // Initialize buckets
    for (i = 0; i < bucketCount; i++) {
        buckets[i] = [];
    }
    // Put the numbers into buckets
    for (i = 0; i < l; i++) {
        // Buckets include the lower bound but not the higher bound, except the top bucket
        try {
            if (data[i] === max) buckets[bucketCount-1].push(data[i]);
            else buckets[((data[i] - min) / inc) | 0].push(data[i]);
        } catch(e) {
            console.warn('Numbers in the data are outside of the min and max values used to bucket the data.');
        }
    }
    return buckets;
}
function bucketNumbersLinearly ( data , bucketCount , min , max ) { var i = 0 , l = data . length ; // If min and max aren't given, set them to the highest and lowest data values if ( typeof min === 'undefined' ) { min = Infinity ; max = - Infinity ; for ( i = 0 ; i < l ; i ++ ) { if ( data [ i ] < min ) min = data [ i ] ; if ( data [ i ] > max ) max = data [ i ] ; } } var inc = ( max - min ) / bucketCount , buckets = new Array ( bucketCount ) ; // Initialize buckets for ( i = 0 ; i < bucketCount ; i ++ ) { buckets [ i ] = [ ] ; } // Put the numbers into buckets for ( i = 0 ; i < l ; i ++ ) { // Buckets include the lower bound but not the higher bound, except the top bucket try { if ( data [ i ] === max ) buckets [ bucketCount - 1 ] . push ( data [ i ] ) ; else buckets [ ( ( data [ i ] - min ) / inc ) | 0 ] . push ( data [ i ] ) ; } catch ( e ) { console . warn ( 'Numbers in the data are outside of the min and max values used to bucket the data.' ) ; } } return buckets ; }
Put numbers into buckets that have equal-size ranges.

@param {Number[]} data
The data to bucket.
@param {Number} bucketCount
The number of buckets to use.
@param {Number} [min]
The minimum allowed data value. Defaults to the smallest value passed.
@param {Number} [max]
The maximum allowed data value. Defaults to the largest value passed.

@return {Number[][]} An array of buckets of numbers.
Put numbers into buckets that have equal - size ranges .