Open this example in the interactive library
Source code
import { Readable } from "node:stream";
import { createInterface } from "node:readline";
const input = Readable.from([
'{"task":"design","needs":[]}\n',
'{"task":"build","needs":["design"]}\n',
'{"task":"test","needs":["build"]}\n',
'{"task":"ship","needs":["build","test"]}\n',
]);
const rows = [];
for await (const line of createInterface({ input, crlfDelay: Infinity })) {
rows.push(JSON.parse(line));
}
const result = rows
.filter(
(r) =>
!["design", "build"].includes(r.task) &&
r.needs.every((n) => ["design", "build"].includes(n)),
)
.map((r) => r.task);
console.log(JSON.stringify(result, null, 2));
Sample output
[ "test" ]
