Sort ascending, by key
See original GitHub issueThis would be so useful to have in D3:
d3.ascendingKey = function(key) {
return function (a, b) {
return a[key] < b[key] ? -1 : a[key] > b[key] ? 1 : a[key] >= b[key] ? 0 : NaN;
};
}
Alternatively also supporting accessor functions, but I think that’s less often needed and possibly inefficient:
d3.ascendingKey = function(key) {
return typeof key == 'function' ? function (a, b) {
return key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : key(a) >= key(b) ? 0 : NaN;
} : function (a, b) {
return a[key] < b[key] ? -1 : a[key] > b[key] ? 1 : a[key] >= b[key] ? 0 : NaN;
};
}
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Python List sort() - Programiz
The sort() method sorts the items of a list in ascending or descending order. ... sort by name (Ascending order) employees.sort(key=get_name).
Read more >ASCENDING KEY and DESCENDING KEY phrases - IBM
ASCENDING KEY and DESCENDING KEY phrases ... Data is arranged in ascending or descending order, depending on the keyword specified, according to the...
Read more >PHP ksort() Function - W3Schools
The ksort() function sorts an associative array in ascending order, according to the key. Tip: Use the krsort() function to sort an associative...
Read more >Python sorting dictionaries: Key [Ascending] and then Value ...
I have looked for ages and have found no actual answers because I can't see any that start with an ascending key and...
Read more >Python | Sort Python Dictionaries by Key or Value
First, sort the keys alphabetically using key_value.iterkeys() function. · Second, sort the keys alphabetically using the sorted (key_value) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A shorter but slightly less efficient version:
In practice I tend to do things like:
I’m not planning on adding these to 3.x, but hopefully 4.0’s module system will make it easier to bundle plugins like d3-jetpack.