File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 1
- const answer = 42 ;
2
- export default answer ;
1
+ import sorted from './sorted.js' ;
2
+
3
+ export { sorted } ;
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments