Skip to content

Commit 65ab2ad

Browse files
🤡 progress: Mock API.
1 parent f93d706 commit 65ab2ad

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
const answer = 42;
2-
export default answer;
1+
import sorted from './sorted.js';
2+
3+
export {sorted};

src/sorted.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Sort the vertices topologically breaking ties according to a given function.
3+
*
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

Comments
 (0)