From 27b94b8cf97fc5d953bde429ee463547c6a57c7c Mon Sep 17 00:00:00 2001 From: TK Date: Sat, 9 Dec 2023 13:28:38 -0300 Subject: [PATCH] * --- .../depth-first-search-cleaner.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 coding_interviews/algoexpert/depth-first-search/depth-first-search-cleaner.js diff --git a/coding_interviews/algoexpert/depth-first-search/depth-first-search-cleaner.js b/coding_interviews/algoexpert/depth-first-search/depth-first-search-cleaner.js new file mode 100644 index 0000000..0e89890 --- /dev/null +++ b/coding_interviews/algoexpert/depth-first-search/depth-first-search-cleaner.js @@ -0,0 +1,19 @@ +class Node { + constructor(name) { + this.name = name; + this.children = []; + } + + addChild(name) { + this.children.push(new Node(name)); + return this; + } + + depthFirstSearch(array) { + array.push(this.name); + for (let child of this.children) { + child.depthFirstSearch(array); + } + return array; + } +}