From ce63de866cb47ef13145a9bb0caf8708b669a4e5 Mon Sep 17 00:00:00 2001 From: Dan B Date: Fri, 25 Jan 2019 20:12:45 -0800 Subject: [PATCH] Update depth-first-search.english.md (#34856) Fixed formatting for the solution to increase readability. It was previously difficult to see since the code was all one line --- .../depth-first-search.english.md | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/curriculum/challenges/english/08-coding-interview-prep/data-structures/depth-first-search.english.md b/curriculum/challenges/english/08-coding-interview-prep/data-structures/depth-first-search.english.md index 15559e6db5..a0a4080520 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/data-structures/depth-first-search.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/data-structures/depth-first-search.english.md @@ -76,7 +76,26 @@ console.log(dfs(exDFSGraph, 3)); ```js -function dfs(graph, root) { var stack = []; var tempV; var visited = []; var tempVNeighbors = []; stack.push(root); while (stack.length > 0) { tempV = stack.pop(); if (visited.indexOf(tempV) == -1) { visited.push(tempV); tempVNeighbors = graph[tempV]; for (var i = 0; i < tempVNeighbors.length; i++) { if (tempVNeighbors[i] == 1) { stack.push(i); }}}} return visited;} +function dfs(graph, root) { + var stack = []; + var tempV; + var visited = []; + var tempVNeighbors = []; + stack.push(root); + while (stack.length > 0) { + tempV = stack.pop(); + if (visited.indexOf(tempV) == -1) { + visited.push(tempV); + tempVNeighbors = graph[tempV]; + for (var i = 0; i < tempVNeighbors.length; i++) { + if (tempVNeighbors[i] == 1) { + stack.push(i); + } + } + } + } + return visited; +} ```