d3: difference between sort and ascending

d3.js

Solution

`Array.sort()` will sort the values alphabetically in ascending order. `Array.sort(d3.ascending)` will sort the values naturally in ascending order. The difference can be seen when you are sorting a list of numbers.

var a = [3,26,1,7];

console.log(a.sort());
// prints [1,26,3,7]

console.log(a.sort(d3.ascending));
// prints [1,3,7,26]

For additional information on how `sort` works, see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort.

Problem

I wanted to know the difference between sort function and ascending function in d3. I am looking for a way to rearrange the data in my table in ascending order of the column selected. Thanks.

Original source