File tree Expand file tree Collapse file tree 1 file changed +6
-11
lines changed
Expand file tree Collapse file tree 1 file changed +6
-11
lines changed Original file line number Diff line number Diff line change 11function circuitSizes ( junctions ) {
2- let circuitCounts = new Map ( ) ;
3- for ( let { circuit } of junctions ) {
4- if ( circuit === null ) continue ;
5- circuitCounts . set ( circuit , ( circuitCounts . get ( circuit ) || 0 ) + 1 ) ;
6- }
7- return Array . from ( circuitCounts . values ( ) ) . sort ( ( a , b ) => b - a ) ;
2+ let connected = junctions . filter ( junction => junction . circuit !== null ) ;
3+ let circuits = Map . groupBy ( connected , junction => junction . circuit ) ;
4+ let sizes = circuits . values ( ) . map ( circuit => circuit . length ) ;
5+ return sizes . toArray ( ) . sort ( ( a , b ) => b - a ) ;
86}
97
108function connectPair ( pair , junctions ) {
@@ -22,11 +20,8 @@ function connectPair(pair, junctions) {
2220}
2321
2422function allConnected ( junctions ) {
25- let firstCircuit = junctions [ 0 ] . circuit ;
26- return (
27- firstCircuit !== null &&
28- junctions . every ( junction => junction . circuit === firstCircuit )
29- ) ;
23+ let { circuit } = junctions [ 0 ] ;
24+ return circuit && junctions . every ( junction => junction . circuit === circuit ) ;
3025}
3126
3227function parse ( input ) {
You can’t perform that action at this time.
0 commit comments