Skip to content

Instantly share code, notes, and snippets.

@lexfrl
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save lexfrl/8cab30c7983e2893caed to your computer and use it in GitHub Desktop.

Select an option

Save lexfrl/8cab30c7983e2893caed to your computer and use it in GitHub Desktop.
static getMapPaths(map) {
map = new Map(map);
getPaths = (map, result = new List([])) => {
if (!Map.isMap(map)) {
return result;
}
return map.flip().toList().reduce((res, k) => {
return res.push(getPaths((map.get(k)), result.push(k)));
}, new List());
};
return getPaths(map).flatten(1);
}
static getMapPaths(map) {
map = new Map(map);
getPaths = (map, result = new List([])) => (
!Map.isMap(map) && result ||
map.flip().toList().reduce(
(res, k) => res.push(getPaths((map.get(k)), result.push(k))),
new List()));
return getPaths(map).flatten(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment