u-toposort
v1.0.1
Published
Universal Topological Sort that supports both JS/TS and HTML imports
Downloads
3
Readme
Universal Topological Sort
Supports both JavaScript/TypeScript and HTML imports
JavaScript/TypeScript import example
installation
npm install u-toposort
Using import
import toposort from 'u-toposort';
const edges: [number, number][] = [
[1, 2],
[2, 3],
];
console.log(toposort(edges));
// [1, 2, 3]
Using require
const toposort = require('u-toposort');
const edges: [string, string][] = [
['1', '2'],
['2', '3'],
];
console.log(toposort(edges));
// ['1', '2', '3']
HTML import example
<html lang="en">
<head>
<script src="https://cdn.jsdelivr.net/npm/u-toposort/build/toposort.min.js"></script>
</head>
<body>
<script>
console.log(
toposort([
[1, 2],
[2, 3],
]),
);
</script>
</body>
</html>
API
this module only export toposort
function (and as default). Here is its
function signature:
function toposort<N>(edges: [N, N][]): N[];
Reference
- https://www.geeksforgeeks.org/topological-sorting-indegree-based-solution/