Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jokeyrhyme/sort-leaves-last.js
Sort an Array of related Objects so that parents always precede their children
https://github.com/jokeyrhyme/sort-leaves-last.js
Last synced: 21 days ago
JSON representation
Sort an Array of related Objects so that parents always precede their children
- Host: GitHub
- URL: https://github.com/jokeyrhyme/sort-leaves-last.js
- Owner: jokeyrhyme
- Created: 2014-06-09T22:11:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-12-16T04:06:49.000Z (almost 8 years ago)
- Last Synced: 2024-04-24T18:08:11.033Z (7 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sort-leaves-last.js
Sort an Array of related Objects so that parents always precede their
children```javascript
/**
* @param {Object[]} nodes an array of objects that need to be sorted
* @returns {Object[]}
*/
return function sortLeavesLast(nodes)
```The nodes may have 0..n children. For my use case, nodes may also have
0..n parents. However, for all nodes, there must be no intersection
between the sets of parents and children (no grand-father paradox!).The Array of nodes may includes nodes from multiple distinct graphs.
For these purposes, a Node is an Object with the `parentNodes` and
`childNodes` properties are Arrays (empty or only containing other
Nodes). The Array of Nodes passed to `sortLeavesLast` must contain all
Nodes in the graph.