function packHistogram(hgram) {
    let r = hgram.ranges;;
    let c = hgram.counts;
    let retgram = {
      range: [r[1], r[r.length - 1]],
      bucket_count: r.length,
      histogram_type: hgram.histogram_type,
      values: {},
      sum: hgram.sum
    };
    let first = true;
    let last = 0;

    for (let i = 0; i < c.length; i++) {
      let value = c[i];
      if (!value)
        continue;

      // add a lower bound
      if (i && first) {
        retgram.values[r[i - 1]] = 0;
      }
      first = false;
      last = i + 1;
      retgram.values[r[i]] = value;
    }

    // add an upper bound
    if (last && last < c.length)
      retgram.values[r[last]] = 0;
    return retgram;
  }
/**
   * When reflecting a histogram into JS, Telemetry hands us an object
   * with the following properties:
   * 
   * - min, max, histogram_type, sum: simple integers;
   * - counts: array of counts for histogram buckets;
   * - ranges: array of calculated bucket sizes.
   * 
   * This format is not straightforward to read and potentially bulky
   * with lots of zeros in the counts array.  Packing histograms makes
   * raw histograms easier to read and compresses the data a little bit.
   *
   * Returns an object:
   * { range: [min, max], bucket_count: <number of buckets>,
   *   histogram_type: <histogram_type>, sum: <sum>
   *   values: { bucket1: count1, bucket2: count2, ... } }
   */
When reflecting a histogram into JS, Telemetry hands us an object
with the following properties.

- min, max, histogram_type, sum: simple integers;
- counts: array of counts for histogram buckets;
- ranges: array of calculated bucket sizes.

This format is not straightforward to read and potentially bulky
with lots of zeros in the counts array.  Packing histograms makes
raw histograms easier to read and compresses the data a little bit.


When reflecting a histogram into JS Telemetry hands us an object with the following properties . - min max histogram_type sum : simple integers ; - counts : array of counts for histogram buckets ; - ranges : array of calculated bucket sizes . This format is not straightforward to read and potentially bulky with lots of zeros in the counts array . Packing histograms makes raw histograms easier to read and compresses the data a little bit .
function packHistogram(hgram) {
    let r = hgram.ranges;;
    let c = hgram.counts;
    let retgram = {
      range: [r[1], r[r.length - 1]],
      bucket_count: r.length,
      histogram_type: hgram.histogram_type,
      values: {},
      sum: hgram.sum
    };
    let first = true;
    let last = 0;
    for (let i = 0; i < c.length; i++) {
      let value = c[i];
      if (!value)
        continue;
      if (i && first) {
        retgram.values[r[i - 1]] = 0;
      }
      first = false;
      last = i + 1;
      retgram.values[r[i]] = value;
    }
    if (last && last < c.length)
      retgram.values[r[last]] = 0;
    return retgram;
  }
function packHistogram ( hgram ) { let r = hgram . ranges ; ; let c = hgram . counts ; let retgram = { range : [ r [ 1 ] , r [ r . length - 1 ] ] , bucket_count : r . length , histogram_type : hgram . histogram_type , values : { } , sum : hgram . sum } ; let first = true ; let last = 0 ; for ( let i = 0 ; i < c . length ; i ++ ) { let value = c [ i ] ; if ( ! value ) continue ; if ( i && first ) { retgram . values [ r [ i - 1 ] ] = 0 ; } first = false ; last = i + 1 ; retgram . values [ r [ i ] ] = value ; } if ( last && last < c . length ) retgram . values [ r [ last ] ] = 0 ; return retgram ; }
When reflecting a histogram into JS, Telemetry hands us an object
 with the following properties:
When reflecting a histogram into JS Telemetry hands us an object with the following properties :
// add a lower bound // add an upper bound