Dev Helpers
← Back

Find terminal tasks in a dependency graph

Find terminal tasks in a dependency graph. Inspect the transformed data in the console.

Open this example in the interactive library

Source code

const rows = [
  { task: "design", needs: [] },
  { task: "build", needs: ["design"] },
  { task: "test", needs: ["build"] },
  { task: "ship", needs: ["build", "test"] },
];
const result = rows
  .filter((r) => !rows.some((x) => x.needs.includes(r.task)))
  .map((r) => r.task);
console.log(JSON.stringify(result, null, 2));

Sample output

[
  "ship"
]