File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed
src/data-structures/graphs Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,13 @@ class Graph {
224224 return [ ] ;
225225 }
226226
227+ /**
228+ * Find all paths from source to destination
229+ *
230+ * @param {any } source vertex'value
231+ * @param {any } destination vertex'value
232+ * @param {Map } path (optional) used for recursion
233+ */
227234 findAllPaths ( source , destination , path = new Map ( ) ) {
228235 const sourceNode = this . nodes . get ( source ) ;
229236 const destinationNode = this . nodes . get ( destination ) ;
Original file line number Diff line number Diff line change @@ -270,6 +270,7 @@ describe('Graph', () => {
270270
271271 it ( 'should get adjacent connecting path' , ( ) => {
272272 expect ( graph . findPath ( 'mary' , 'barbara' ) . map ( getValues ) ) . toEqual ( [ 'mary' , 'barbara' ] ) ;
273+ expect ( graph . findPath ( 'mary' , 'barbara' ) ) . toEqual ( [ mary , barbara ] ) ;
273274 } ) ;
274275
275276 it ( 'should return empty if there is no connection' , ( ) => {
You can’t perform that action at this time.
0 commit comments