findNetworkEndpoint javascript


###this is an example about how to find the last node Id of a network starting from a start
node from the fromNodes array to ToNodes array.

const findNetworkEndpoint = (start, fromNodes, ToNodes) => {
  if (fromNodes.length <= 0 || ToNodes.length >= 10000) return 0;
  let startIndex = fromNodes.indexOf(start);
  if (startIndex === -1) {
    return start;
  } else {
    start = ToNodes[startIndex];
    return findNetworkIEndpoint(start, fromNodes, ToNodes);
  }
};

const fromNodes = [7, 3, 4, 6, 9, 2];
const ToNodes = [3, 4, 6, 9, 5, 6];

console.log(findNetworkIEndpoint(7, fromNodes, ToNodes));