---
id: 69c918841987bf16c1d1babf
title: Step 8
challengeType: 1
dashedName: step-8
---

# --description--

You also need to track the actual path taken to reach each node. You will store a list of paths where each entry is an array of node indices representing the route taken.

Initially, each node's path will just contain itself. You can create this structure using `Array.from()`:

```js
Array.from({ length: n }, (_, i) => [i]);
```

This creates an array of `n` elements, where the element at index `i` is `[i]`.

Still within the `shortestPath` function, create a variable named `paths` and assign it `Array.from({ length: n }, (_, i) => [i])`.

# --hints--

You should create a variable `paths` inside the `shortestPath` function.

```js
assert.match(
  __helpers.removeJSComments(shortestPath.toString()),
  /(const|let|var)\s+paths\s*=/
);
```

Your `paths` variable should be initialized using `Array.from`.

```js
assert.match(
  __helpers.removeJSComments(shortestPath.toString()),
  /paths\s*=\s*Array\.from/
);
```

Your `paths` variable should use `{ length: n }` as the first argument to `Array.from`.

```js
assert.match(
  __helpers.removeJSComments(shortestPath.toString()),
  /Array\.from\s*\(\s*\{\s*length\s*:\s*n\s*\}/
);
```

The second argument to `Array.from` should be a callback `(_, i) => [i]`, where `_` is a placeholder for the unused element and `i` is the index. It should return `[i]`.

```js
assert.match(
  __helpers.removeJSComments(shortestPath.toString()),
  /Array\.from\s*\([\s\S]*?,\s*function\s*\(\s*\w+\s*,\s*(\w+)\s*\)\s*\{[\s\S]*?return\s*\[\s*\1\s*\]|Array\.from\s*\([\s\S]*?,\s*\(\s*\w+\s*,\s*\w+\s*\)\s*=>\s*\[\s*\w+\s*\]/
);
```

# --seed--

## --seed-contents--

```js
const INF = Infinity;
const adjMatrix = [
  [0, 5, 3, INF, 11, INF],
  [5, 0, 1, INF, INF, 2],
  [3, 1, 0, 1, 5, INF],
  [INF, INF, 1, 0, 9, 3],
  [11, INF, 5, 9, 0, INF],
  [INF, 2, INF, 3, INF, 0],
];

function shortestPath(matrix, startNode, targetNode = null) {
  const n = matrix.length;
  const distances = new Array(n).fill(INF);
  distances[startNode] = 0;
  --fcc-editable-region--

  --fcc-editable-region--
}
```
