Code coverage report for lib/algorithms/4-searching/depthFirstSearch.js

Statements: 90% (18 / 20)      Branches: 70% (7 / 10)      Functions: 100% (2 / 2)      Lines: 89.47% (17 / 19)      Ignored: none     

All files » lib/algorithms/4-searching/ » depthFirstSearch.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 351   1 3   3       3 13   13     13 2       1   1 29   21 21 21     21       1
var Queue = require("../../../lib/dataStructures/queue.js");
 
var depthFirstSearch = function(root, matches) {
    var nodeQueue = new Queue();
 
    Iif (found(root)) {
        return true;
    }
 
    while (!nodeQueue.isEmpty()) {
        var node = nodeQueue.pop();
 
        Iif(found(node.left)) {
            return true;
        }
        if(found(node.right)) {
            return true;
        }
    }
 
    return false;
 
    function found(node) {
        if (node === null) return false;
 
        Eif (!node.visited) {
            node.visited = true;
            nodeQueue.push(node);
        }
 
        return matches(node.data);
    }
};
 
module.exports = depthFirstSearch;