function numberOfTrips(start, end, currentDepth = 0, maxStops = 1) { //todo
  let routes = 0;

  if (testHashMap.hasOwnProperty(start)) {
    currentDepth++;
    if (currentDepth > maxStops) { //end of the recursion
      return 0;
    }
    testHashMap[start]._visited = true;
    const nextNodes = Object.keys(testHashMap[start]);
    nextNodes.forEach((keyOfNextNode) => {
      if (keyOfNextNode === end) {
        routes++;
      } else {
        routes += numberOfTrips(keyOfNextNode, end, currentDepth, maxStops); //recursion
      }
    });
  } else {
    throw new Error("NO SUCH ROUTE");
  }
  testHashMap[start]._visited = false;

  return routes;
}
/**
 * Find the amount of possible of routes when given a maxStops.
 * @param start
 * @param end
 * @param currentDepth
 * @param maxStops
 * @returns {number}
 */
Find the amount of possible of routes when given a maxStops.
Find the amount of possible of routes when given a maxStops .
function numberOfTrips(start, end, currentDepth = 0, maxStops = 1) { 
  let routes = 0;
  if (testHashMap.hasOwnProperty(start)) {
    currentDepth++;
    if (currentDepth > maxStops) { 
      return 0;
    }
    testHashMap[start]._visited = true;
    const nextNodes = Object.keys(testHashMap[start]);
    nextNodes.forEach((keyOfNextNode) => {
      if (keyOfNextNode === end) {
        routes++;
      } else {
        routes += numberOfTrips(keyOfNextNode, end, currentDepth, maxStops); 
      }
    });
  } else {
    throw new Error("NO SUCH ROUTE");
  }
  testHashMap[start]._visited = false;
  return routes;
}
function numberOfTrips ( start , end , currentDepth = 0 , maxStops = 1 ) { let routes = 0 ; if ( testHashMap . hasOwnProperty ( start ) ) { currentDepth ++ ; if ( currentDepth > maxStops ) { return 0 ; } testHashMap [ start ] . _visited = true ; const nextNodes = Object . keys ( testHashMap [ start ] ) ; nextNodes . forEach ( ( keyOfNextNode ) => { if ( keyOfNextNode === end ) { routes ++ ; } else { routes += numberOfTrips ( keyOfNextNode , end , currentDepth , maxStops ) ; } } ) ; } else { throw new Error ( "NO SUCH ROUTE" ) ; } testHashMap [ start ] . _visited = false ; return routes ; }
Find the amount of possible of routes when given a maxStops.
Find the amount of possible of routes when given a maxStops .
//todo //end of the recursion //recursion