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 {
224
224
return [];
225
225
}
226
226
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
+ */
227
234
findAllPaths(source, destination, path = new Map()) {
228
235
const sourceNode = this.nodes.get(source);
229
236
const destinationNode = this.nodes.get(destination);
Original file line number Diff line number Diff line change @@ -270,6 +270,7 @@ describe('Graph', () => {
270
270
271
271
it('should get adjacent connecting path', () => {
272
272
expect(graph.findPath('mary', 'barbara').map(getValues)).toEqual(['mary', 'barbara']);
273
+ expect(graph.findPath('mary', 'barbara')).toEqual([mary, barbara]);
273
274
});
274
275
275
276
it('should return empty if there is no connection', () => {
You can’t perform that action at this time.
0 commit comments