mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 22:27:01 +01:00
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
21 lines
779 B
JavaScript
21 lines
779 B
JavaScript
// Evaluates each card example and reports its JSON.stringify'd return value.
|
|
// Input (stdin): [{"id": "...", "code": "<function body with return>"}]
|
|
// Output (stdout): [{"id": "...", "ok": true, "value": "..."} | {"ok": false, "error": "..."}]
|
|
"use strict";
|
|
|
|
const chunks = [];
|
|
process.stdin.on("data", (c) => chunks.push(c));
|
|
process.stdin.on("end", () => {
|
|
const items = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
const out = items.map(({ id, code }) => {
|
|
try {
|
|
const result = new Function(code)();
|
|
const value = result === undefined ? "undefined" : JSON.stringify(result);
|
|
return { id, ok: true, value };
|
|
} catch (err) {
|
|
return { id, ok: false, error: String(err) };
|
|
}
|
|
});
|
|
process.stdout.write(JSON.stringify(out));
|
|
});
|