lib/core/tasks.js
function(node, path) {

    // Validate.
    if (!isBranch(node)) {
      assert(false);
    }
    if (path.length === 0) {
      assert(false);
    }

    // Partition head and tail.
    var hd = path[0];
    var tl = path.slice(1);

    // Find a child of node that matches path.
    var cursor = _.find(node.children, function(obj) {
      return getName(obj) === hd;
    });

    // Conflicting tasks exist in task tree.
    if (cursor && isTask(cursor)) {

      throw new Error('Task already exists: ' + task.path.join(' -> '));

    }

    // Continue.
    if (tl.length === 0) {

      // We are at the end of the path.
      task.path = [hd];

      if (cursor) {

        addChild(cursor, task);

      } else {

        addChild(node, task);

      }

      return;

    } else {

      // We are NOT at the end of the path.
      if (!cursor) {

        cursor = createBranch(hd);
        addChild(node, cursor);

      }

      return rec(cursor, tl);

    }

  }
function(node, path) {

    // Validate.
    if (!isBranch(node)) {
      assert(false);
    }
    if (path.length === 0) {
      assert(false);
    }

    // Partition head and tail.
    var hd = path[0];
    var tl = path.slice(1);

    // Find a child of node that matches path.
    var cursor = _.find(node.children, function(obj) {
      return getName(obj) === hd;
    });

    // Conflicting tasks exist in task tree.
    if (cursor && isTask(cursor)) {

      throw new Error('Task already exists: ' + task.path.join(' -> '));

    }

    // Continue.
    if (tl.length === 0) {

      // We are at the end of the path.
      task.path = [hd];

      if (cursor) {

        addChild(cursor, task);

      } else {

        addChild(node, task);

      }

      return;

    } else {

      // We are NOT at the end of the path.
      if (!cursor) {

        cursor = createBranch(hd);
        addChild(node, cursor);

      }

      return rec(cursor, tl);

    }

  }
function ( node , path ) { // Validate. if ( ! isBranch ( node ) ) { assert ( false ) ; } if ( path . length === 0 ) { assert ( false ) ; } // Partition head and tail. var hd = path [ 0 ] ; var tl = path . slice ( 1 ) ; // Find a child of node that matches path. var cursor = _ . find ( node . children , function ( obj ) { return getName ( obj ) === hd ; } ) ; // Conflicting tasks exist in task tree. if ( cursor && isTask ( cursor ) ) { throw new Error ( 'Task already exists: ' + task . path . join ( ' -> ' ) ) ; } // Continue. if ( tl . length === 0 ) { // We are at the end of the path. task . path = [ hd ] ; if ( cursor ) { addChild ( cursor , task ) ; } else { addChild ( node , task ) ; } return ; } else { // We are NOT at the end of the path. if ( ! cursor ) { cursor = createBranch ( hd ) ; addChild ( node , cursor ) ; } return rec ( cursor , tl ) ; } }
Recursive function for placing task in task tree.
Recursive function for placing task in task tree .