Working With Arrays

Showcases d3 utility array functions

Api Reference @link https://github.com/mbostock/d3/wiki/Arrays

Back to table of contents
  // To See Output Requires google chrome or firefox (with firebug plugin)
  // debug variable in console through console.log
  // see link: http://stackoverflow.com/questions/4743730/what-is-console-log-and-how-do-i-use-it
  var data = [10, 20, 30, 40, 50];
  // gets first element returns value : 10, additionally alters data array and removes first element 10.
  data.shift();
  // let's reintialize the data array back to its original state.
  var data = [10, 20, 30, 40, 50];
  // returns an array that is sorted descending (output): [50, 40, 30, 20, 10]
  data.sort(d3.descending);
  // Returns the minimum value in the given array (output): 10
  d3.min(data);
  // Returns the maximum value in the given array (output): 50
  d3.max(data);
  // Returns the minimum and maximum value in the given array (output) : [10, 50]
  d3.extent(data);
  // Returns the sum of the given array. (output) : 150
  d3.sum(data);
  // Returns the mean of the given array. (output) : 30
  d3.mean(data);
  // Returns the median of the given array. (output) : 30
  d3.median(data);
  // Randomizes the order of the specified array
  d3.shuffle(data);