File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -27,20 +27,20 @@ class Node {
2727 }
2828
2929 toArray ( ) {
30- const string = [ ] ;
30+ const array = [ ] ;
3131 const queue = new Queue ( ) ;
3232 queue . add ( this ) ;
3333
3434 while ( ! queue . isEmpty ( ) ) {
3535 const node = queue . remove ( ) ;
36- string . push ( node . data ) ;
36+ array . push ( node . data ) ;
3737
3838 node . adjacents . forEach ( function ( adj ) {
3939 if ( adj ) { queue . add ( adj ) ; }
4040 } ) ;
4141 }
4242
43- return string ;
43+ return array ;
4444 }
4545
4646 toString ( ) {
@@ -73,12 +73,12 @@ class Graph {
7373 let sourceNode , targetNode ;
7474
7575 sourceNode = this . getNode ( source ) ;
76- if ( target ) targetNode = this . getNode ( target ) ;
76+ if ( typeof target !== 'undefined' ) targetNode = this . getNode ( target ) ;
7777
78- if ( target ) sourceNode . adjacents . push ( targetNode ) ;
78+ if ( typeof target !== 'undefined' ) sourceNode . adjacents . push ( targetNode ) ;
7979
8080 this . nodes . set ( sourceNode . data , sourceNode ) ;
81- if ( target ) this . nodes . set ( targetNode . data , targetNode ) ;
81+ if ( typeof target !== 'undefined' ) this . nodes . set ( targetNode . data , targetNode ) ;
8282
8383 return sourceNode ;
8484 }
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ describe('Graph', function () {
1212 describe ( 'add' , function ( ) {
1313 it ( 'should add two elements' , function ( ) {
1414 graph . add ( 0 , 1 ) ;
15-
15+ expect ( Array . from ( graph . nodes . keys ( ) ) ) . to . eql ( [ 0 , 1 ] ) ;
1616 } ) ;
1717
1818 it ( 'should allow one element to have two children' , function ( ) {
You can’t perform that action at this time.
0 commit comments