@paybase/machine
Advanced tools
Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "@paybase/machine", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "async/await finite state machine factory", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -44,13 +44,12 @@ const { | ||
const shortestPath = (joins) => { | ||
function recurse(from, to, visited = new Set(), arr = [ to ]) { | ||
return !visited.has(to) | ||
function recurse(from, to, visited = [], arr = [ to ]) { | ||
return !visited.includes(to) | ||
? joins | ||
.filter(([ , v ]) => v.includes(to)) | ||
.reduce((acc, [ k ]) => { | ||
visited.add(to); | ||
return k !== from | ||
? acc.concat(recurse(from, k, visited, [ k ].concat(arr))) | ||
? acc.concat(recurse(from, k, [ to, ...visited ], [ k ].concat(arr))) | ||
: acc.concat([ [ k ].concat(arr) ]); | ||
}, []) | ||
.sort((a, b) => a.length > b.length) | ||
.sort((a, b) => a.length - b.length) | ||
: []; | ||
@@ -68,3 +67,3 @@ } | ||
const recurse = shortestPath(joins); | ||
// if a path is found, get pairs of the sequence, ie. [ [ A, B ], [ B, C ] ] | ||
@@ -71,0 +70,0 @@ const getPathPairs = x => !x.some(y => y === undefined) |
Sorry, the diff of this file is not supported yet
26498
362