---
id: 69c918841987bf16c1d1bac6
title: Step 15
challengeType: 1
dashedName: step-15
---

# --description--

Once you've confirmed a valid node was found, mark it as visited so the algorithm won't process it again.

After the `if` statement with the condition `current === -1`, set `visited[current]` to `true`.

# --hints--

You should set `visited[current]` to `true`.

```js
assert.match(
  __helpers.removeJSComments(shortestPath.toString()),
  /visited\s*\[\s*current\s*\]\s*=\s*true/
);
```

# --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;
  const paths = Array.from({ length: n }, (_, i) => [i]);
  const visited = new Array(n).fill(false);

  for (let i = 0; i < n; i++) {
    let minDistance = INF;
    let current = -1;
    for (let nodeNo = 0; nodeNo < n; nodeNo++) {
      if (!visited[nodeNo] && distances[nodeNo] < minDistance) {
        minDistance = distances[nodeNo];
        current = nodeNo;
      }
    }

    if (current === -1) {
      break;
    }
    --fcc-editable-region--

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