Path.mjs 405 B

123456789101112131415161718192021222324
  1. /**
  2. * Given a Path and a key, return a new Path containing the new key.
  3. */
  4. export function addPath(prev, key) {
  5. return {
  6. prev: prev,
  7. key: key
  8. };
  9. }
  10. /**
  11. * Given a Path, return an Array of the path keys.
  12. */
  13. export function pathToArray(path) {
  14. var flattened = [];
  15. var curr = path;
  16. while (curr) {
  17. flattened.push(curr.key);
  18. curr = curr.prev;
  19. }
  20. return flattened.reverse();
  21. }