Simple histogram algorithm in Javascript
问题 Im creating a histogram algorithm. Im following the solution offered here. I want to simply count the number of times each value has occurred. However I cant quite get the algorithm right. My code is: var values = [2, 4, 6, 3, 3]; var val_max = 6; var val_min = 2; var num_bins = parseInt(val_max - val_min + 1); console.log('num_bins is ', num_bins); var bin_width = (val_max-val_min)/num_bins; console.log('bin_width is ', bin_width); var to_plot = []; for (var i = 0; i < num_bins; i++) { to