UNPKG

405 BJavaScriptView Raw
1/**
2 * Given a Path and a key, return a new Path containing the new key.
3 */
4export 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
14export function pathToArray(path) {
15 var flattened = [];
16 var curr = path;
17
18 while (curr) {
19 flattened.push(curr.key);
20 curr = curr.prev;
21 }
22
23 return flattened.reverse();
24}