Skip to content

Instantly share code, notes, and snippets.

@mlevans
Created May 10, 2012 00:21
Show Gist options
  • Save mlevans/2650008 to your computer and use it in GitHub Desktop.
Save mlevans/2650008 to your computer and use it in GitHub Desktop.
Simple Sorting Tutorial
// Load d3
var val_arr = [];
function sortFunction(a,b) {
return a - b;
}
function loadData(){
d3.csv('data.csv',function(data){
// Async
data.forEach(function(d) {
val_arr.push(parseFloat(d.property));
})
sortValues(val_arr);
});
}
function sortValues(arr) {
var sorted_values = arr.sort(sortFunction);
console.log(sorted_values);
console.log(sorted_values.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment