We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f93d706 commit 65ab2adCopy full SHA for 65ab2ad
src/index.js
@@ -1,2 +1,3 @@
1
-const answer = 42;
2
-export default answer;
+import sorted from './sorted.js';
+
3
+export {sorted};
src/sorted.js
@@ -0,0 +1,16 @@
+/**
+ * Sort the vertices topologically breaking ties according to a given function.
+ *
4
+ * @param {Iterable<any>} edges - The input graph as a list of edges.
5
+ * @param {(a: any, b: any) => Number} breakTies - The function to break ties.
6
+ * @returns {Iterable<any>} The vertices sorted in topological order.
7
+ */
8
+export default function sorted(edges, breakTies = (_a, _b) => -1) {
9
+ const vertices = new Set();
10
+ for (const [u, v] of edges) {
11
+ vertices.add(u);
12
+ vertices.add(v);
13
+ }
14
15
+ return [...vertices].sort(breakTies)[Symbol.iterator]();
16
+}
0 commit comments