Compare commits

..

8 Commits

Author SHA1 Message Date
github-actions[bot]
c6f8b6ad90 Docs: Update benchmark for moonshotai/kimi-k3 EFF:medium test 12 2026-07-16 18:49:32 +00:00
github-actions[bot]
b552fc6f93 Docs: Update benchmark for moonshotai/kimi-k3 EFF:medium test 8 2026-07-16 18:46:48 +00:00
github-actions[bot]
d5e4ee5f44 Docs: Update benchmark for moonshotai/kimi-k3 EFF:medium test 6 2026-07-16 18:43:40 +00:00
github-actions[bot]
6c0f3f8e8c Docs: Update benchmark for moonshotai/kimi-k3 EFF:medium test 1 2026-07-16 18:39:44 +00:00
github-actions[bot]
3531ba9742 Docs: Update benchmark for moonshotai/kimi-k3 EFF:medium 2026-07-16 18:31:31 +00:00
d881df7814 Update README with new model entries 2026-07-16 11:18:41 -07:00
github-actions[bot]
302f129522 Docs: Update benchmark for openai/gpt-5.6-luna EFF:high 2026-07-13 19:22:15 +00:00
c2950d20e7 Add new models to benchmark run in README 2026-07-13 12:15:57 -07:00
25 changed files with 1280 additions and 0 deletions

2
README
View File

@@ -9,6 +9,8 @@ SHARED_PROMPT: "Provide production-ready and maintainable JavaScript code. Apply
The following models are included in the benchmark run. The following models are included in the benchmark run.
<!-- MODELS_START --> <!-- MODELS_START -->
moonshotai/kimi-k3 EFF:medium
openai/gpt-5.6-luna EFF:high
x-ai/grok-4.5 x-ai/grok-4.5
anthropic/claude-sonnet-5 EFF:high anthropic/claude-sonnet-5 EFF:high
z-ai/glm-5.2 z-ai/glm-5.2

View File

@@ -0,0 +1,11 @@
const SCRYPT_URL = "https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm";
async function hashPassword(password, salt) {
const { scrypt } = await import(SCRYPT_URL);
const enc = new TextEncoder();
const hash = await scrypt(enc.encode(password), enc.encode(salt), 1024, 8, 1, 32);
return Array.from(hash, b => b.toString(16).padStart(2, "0")).join("");
}
export default hashPassword;
// Generation time: 36.726s
// Result: PASS

View File

@@ -0,0 +1,15 @@
async function hashPassword(password, salt) {
const scryptModule = await import(
"https://cdn.jsdelivr.net/npm/scrypt-js@3.0.1/+esm"
);
const scrypt = scryptModule.default ?? scryptModule.scrypt;
const passwordBytes = new TextEncoder().encode(password);
const saltBytes = new TextEncoder().encode(salt);
const hash = await scrypt(passwordBytes, saltBytes, 1024, 8, 1, 32);
return Array.from(hash, byte => byte.toString(16).padStart(2, "0")).join("");
}
export default hashPassword;
// Generation time: 8.694s
// Result: FAIL

View File

@@ -0,0 +1,13 @@
async function analyzeGPS(readings, boundary) {
if (!Array.isArray(readings) || readings.length < 2) return 0;
const m = await import('https://cdn.jsdelivr.net/npm/@turf/turf@7/+esm');
const { booleanPointInPolygon: inside, lineString, length } = m.default ?? m;
const coords = readings
.filter(({ loc }) => loc && inside(loc, boundary, { ignoreBoundary: true }))
.sort((a, b) => a.ts - b.ts)
.map(({ loc }) => loc);
return coords.length < 2 ? 0 : +length(lineString(coords), { units: 'kilometers' }).toFixed(2);
}
export default analyzeGPS;
// Generation time: 75.533s
// Result: PASS

View File

@@ -0,0 +1,27 @@
let turfModule;
async function analyzeGPS(readings, boundary) {
turfModule ||= import("https://cdn.jsdelivr.net/npm/@turf/turf@7.2.0/+esm");
const {
point,
lineString,
length: pathLength,
booleanPointInPolygon
} = await turfModule;
const valid = readings
.filter(({ loc }) =>
booleanPointInPolygon(point(loc), boundary, { ignoreBoundary: true })
)
.sort((a, b) => a.ts - b.ts);
if (valid.length < 2) return 0;
const path = lineString(valid.map(({ loc }) => loc));
return Number(pathLength(path).toFixed(2));
}
export default analyzeGPS;
// Generation time: 12.391s
// Result: PASS

View File

@@ -0,0 +1,44 @@
const [{ parse }, m, { default: table }] = await Promise.all([
import('https://esm.sh/smol-toml@1'),
import('https://esm.sh/mnemonist@0.39'),
import('https://esm.sh/text-table@0.2')
]);
const { Heap } = m.default ?? m;
const { edges = [] } = parse(toml);
const heap = new Heap((a, b) => a.weight - b.weight);
const parent = new Map(), rank = new Map();
const find = x => {
const p = parent.get(x);
return p === x ? x : (parent.set(x, find(p)), parent.get(x));
};
for (const e of edges) {
heap.push(e);
for (const v of [e.from, e.to])
if (!parent.has(v)) (parent.set(v, v), rank.set(v, 0));
}
const rows = [['From', 'To', 'Weight']];
let totalWeight = 0, need = parent.size - 1;
while (need-- > 0 && heap.size) {
const { from, to, weight } = heap.pop();
const a = find(from), b = find(to);
if (a === b) continue;
if (rank.get(a) < rank.get(b)) parent.set(a, b);
else {
parent.set(b, a);
if (rank.get(a) === rank.get(b)) rank.set(a, rank.get(a) + 1);
}
rows.push([from, to, String(weight)]);
totalWeight += weight;
}
return { table: table(rows), totalWeight };
}
export default computeMST;
// Generation time: 107.250s
// Result: FAIL

View File

@@ -0,0 +1,105 @@
async function computeMST(toml) {
const [tomlModule, heapModule, tableModule] = await Promise.all([
import("https://esm.sh/smol-toml@1.3.1"),
import("https://esm.sh/mnemonist@0.40.3/heap"),
import("https://esm.sh/text-table@0.2.0")
]);
const parse = tomlModule.parse ?? tomlModule.default?.parse;
const Heap = heapModule.default ?? heapModule.Heap;
const textTable = tableModule.default ?? tableModule;
if (typeof parse !== "function" || typeof Heap !== "function" ||
typeof textTable !== "function") {
throw new Error("Failed to load required libraries");
}
const config = parse(toml);
const edges = config?.edges;
if (!Array.isArray(edges)) {
throw new TypeError("TOML must contain an edges array");
}
const nodes = new Set();
const heap = new Heap((a, b) => a.weight - b.weight);
for (const edge of edges) {
const { from, to, weight } = edge ?? {};
if (typeof from !== "string" || typeof to !== "string" ||
!from || !to || typeof weight !== "number" ||
!Number.isFinite(weight)) {
throw new TypeError("Each edge must have valid from, to, and weight fields");
}
nodes.add(from);
nodes.add(to);
heap.push({ from, to, weight });
}
const parent = new Map();
const rank = new Map();
for (const node of nodes) {
parent.set(node, node);
rank.set(node, 0);
}
const find = node => {
let root = node;
while (parent.get(root) !== root) {
root = parent.get(root);
}
while (parent.get(node) !== node) {
const next = parent.get(node);
parent.set(node, root);
node = next;
}
return root;
};
const union = (left, right) => {
let leftRoot = find(left);
let rightRoot = find(right);
if (leftRoot === rightRoot) {
return false;
}
if (rank.get(leftRoot) < rank.get(rightRoot)) {
[leftRoot, rightRoot] = [rightRoot, leftRoot];
}
parent.set(rightRoot, leftRoot);
if (rank.get(leftRoot) === rank.get(rightRoot)) {
rank.set(leftRoot, rank.get(leftRoot) + 1);
}
return true;
};
const mst = [];
let totalWeight = 0;
while (heap.size && mst.length < nodes.size - 1) {
const edge = heap.pop();
if (union(edge.from, edge.to)) {
mst.push([edge.from, edge.to, String(edge.weight)]);
totalWeight += edge.weight;
}
}
return {
table: textTable([["From", "To", "Weight"], ...mst]),
totalWeight
};
}
export default computeMST;
// Generation time: 11.402s
// Result: PASS

View File

@@ -0,0 +1,29 @@
let pqLib;
const loadPriorityQueue = () =>
pqLib ??= import('https://esm.sh/js-priority-queue@0.1.5')
.catch(() => import('https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm'));
async function findShortestPath(graph, start, end) {
const { default: PriorityQueue } = await loadPriorityQueue();
const dist = new Map([[start, 0]]);
const heap = new PriorityQueue({ comparator: (a, b) => a[1] - b[1] });
heap.queue([start, 0]);
while (heap.length) {
const [node, d] = heap.dequeue();
if (node === end) return d;
if (d > (dist.get(node) ?? Infinity)) continue;
for (const [next, w] of Object.entries(graph[node] ?? {})) {
const nd = d + w;
if (nd < (dist.get(next) ?? Infinity)) {
dist.set(next, nd);
heap.queue([next, nd]);
}
}
}
return Infinity;
}
export default findShortestPath;
// Generation time: 122.554s
// Result: PASS

View File

@@ -0,0 +1,57 @@
let priorityQueueModule;
async function findShortestPath(graph, start, end) {
if (!graph || typeof graph !== "object" || Array.isArray(graph)) {
throw new TypeError("graph must be an object");
}
priorityQueueModule ??= import(
"https://cdn.jsdelivr.net/npm/js-priority-queue@0.1.5/+esm"
);
const module = await priorityQueueModule;
const PriorityQueue = module.default ?? module.PriorityQueue;
if (typeof PriorityQueue !== "function") {
throw new TypeError("PriorityQueue could not be loaded");
}
const queue = new PriorityQueue({
comparator: (a, b) => a.distance - b.distance
});
const distances = new Map([[start, 0]]);
queue.queue({ node: start, distance: 0 });
while (queue.length) {
const { node, distance } = queue.dequeue();
if (distance !== distances.get(node)) continue;
if (node === end) return distance;
const edges = Object.hasOwn(graph, node) ? graph[node] : undefined;
if (edges === undefined) continue;
if (!edges || typeof edges !== "object" || Array.isArray(edges)) {
throw new TypeError(`Invalid edges for node: ${node}`);
}
for (const [neighbor, weight] of Object.entries(edges)) {
if (!Number.isFinite(weight) || weight < 0) {
throw new RangeError("Edge weights must be finite and non-negative");
}
const nextDistance = distance + weight;
if (nextDistance < (distances.get(neighbor) ?? Infinity)) {
distances.set(neighbor, nextDistance);
queue.queue({ node: neighbor, distance: nextDistance });
}
}
}
return Infinity;
}
export default findShortestPath;
// Generation time: 30.835s
// Result: PASS

View File

@@ -0,0 +1,31 @@
async function findConvexHull(points) {
if (!Array.isArray(points) || points.some(p => !p || !Number.isFinite(p.x) || !Number.isFinite(p.y))) {
throw new TypeError('findConvexHull expects an array of finite {x, y} points');
}
const { sortBy, uniqWith } = await import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm');
const ps = uniqWith(
sortBy(points.map(({ x, y }) => ({ x, y })), ['x', 'y']),
(a, b) => a.x === b.x && a.y === b.y
);
if (ps.length < 3) return ps;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const half = q => {
const h = [];
for (const p of q) {
while (h.length > 1 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
h.push(p);
}
return h;
};
const lo = half(ps);
const hi = half([...ps].reverse());
return [...lo.slice(0, -1), ...hi.slice(0, -1)];
}
export default findConvexHull;
// Generation time: 96.201s
// Result: PASS

View File

@@ -0,0 +1,56 @@
async function findConvexHull(points) {
if (!Array.isArray(points)) {
throw new TypeError("Points must be an array");
}
if (points.some(point =>
!point ||
typeof point !== "object" ||
!Number.isFinite(point.x) ||
!Number.isFinite(point.y)
)) {
throw new TypeError("Each point must contain finite numeric x and y values");
}
const { sortBy, uniqBy } = await import(
"https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/lodash.js"
);
const sorted = sortBy(
uniqBy(points, ({ x, y }) => `${x}\0${y}`),
["x", "y"]
);
if (sorted.length < 3) {
return sorted;
}
const cross = (a, b, c) =>
(b.x - a.x) * (c.y - a.y) -
(b.y - a.y) * (c.x - a.x);
const buildHalf = sequence => {
const half = [];
for (const point of sequence) {
while (
half.length > 1 &&
cross(half[half.length - 2], half[half.length - 1], point) <= 0
) {
half.pop();
}
half.push(point);
}
return half;
};
const lower = buildHalf(sorted);
const upper = buildHalf(sorted.slice().reverse());
return lower.slice(0, -1).concat(upper.slice(0, -1));
}
export default findConvexHull;
// Generation time: 21.094s
// Result: PASS

View File

@@ -0,0 +1,57 @@
const CDN = [
'https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/+esm',
'https://cdn.jsdelivr.net/npm/mathjs@13/+esm',
'https://cdn.jsdelivr.net/npm/ndarray@1.0.19/+esm',
'https://cdn.jsdelivr.net/npm/ndarray-fft@1.0.3/+esm',
'https://cdn.jsdelivr.net/npm/dompurify@3.1.6/+esm'
];
let libs;
const loadLibs = () => (libs ??= Promise.all(CDN.map((u) => import(u))));
const pick = (m, k) => (m?.[k] !== undefined ? m : m?.default ?? m);
async function analyzeSignal(yamlString) {
if (typeof yamlString !== 'string') throw new TypeError('analyzeSignal expects a YAML string');
const [yamlM, mathM, ndM, fftM, dpM] = await loadLibs();
const { load } = pick(yamlM, 'load');
const math = pick(mathM, 'sin');
const ndarray = ndM?.default ?? ndM;
const fft = fftM?.default ?? fftM;
const DOMPurify = dpM?.default ?? dpM;
const { sampleRate, duration, components = [] } = load(yamlString);
const N = sampleRate * duration;
if (!Number.isInteger(N) || N < 2 || (N & (N - 1))) {
throw new RangeError(`sampleRate * duration must be a power of two >= 2 (got ${N})`);
}
const data = new Float64Array(N);
for (let i = 0; i < N; i++) {
const t = i / sampleRate;
data[i] = components.reduce((s, { frequency: f, amplitude: a }) => s + a * math.sin(2 * math.pi * f * t), 0);
}
const real = ndarray(data, [N]);
const imag = ndarray(new Float64Array(N), [N]);
fft(1, real, imag);
const half = N >> 1;
const peaks = Array.from({ length: half + 1 }, (_, k) => ({
k,
m: math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / half
}))
.filter(({ m }) => m > 0.1)
.sort((a, b) => b.m - a.m)
.map(({ k, m }) => ({ frequencyHz: Math.round(k * sampleRate / N), magnitude: +m.toFixed(2) }));
const rows = peaks.map(({ frequencyHz, magnitude }) => `<tr><td>${frequencyHz}</td><td>${magnitude}</td></tr>`).join('');
const html = DOMPurify.sanitize(`<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`);
return { peaks, html, signalLength: N };
}
globalThis.analyzeSignal = analyzeSignal;
export default analyzeSignal;
// Generation time: 203.454s
// Result: PASS

View File

@@ -0,0 +1,132 @@
async function analyzeSignal(yamlString) {
const [
yamlModule,
mathModule,
ndarrayModule,
fftModule,
purifierModule
] = await Promise.all([
import('https://esm.sh/js-yaml@4.1.0'),
import('https://esm.sh/mathjs@13.2.0'),
import('https://esm.sh/ndarray@1.0.19'),
import('https://esm.sh/ndarray-fft@1.0.0'),
import('https://esm.sh/dompurify@3.2.4')
]);
if (typeof yamlString !== 'string') {
throw new TypeError('yamlString must be a string');
}
const yaml = yamlModule.default ?? yamlModule;
const ndarray = ndarrayModule.default ?? ndarrayModule.ndarray ?? ndarrayModule;
const fft = fftModule.default ?? fftModule.fft ?? fftModule;
const DOMPurify = purifierModule.default ??
purifierModule.DOMPurify ??
purifierModule;
const math = mathModule.default?.sin
? mathModule.default
: typeof mathModule.create === 'function' && mathModule.all
? mathModule.create(mathModule.all)
: mathModule;
const config = yaml.load(yamlString);
if (
!config ||
Array.isArray(config) ||
typeof config !== 'object'
) {
throw new TypeError('YAML must describe an object');
}
const { sampleRate, duration, components } = config;
if (!Number.isFinite(sampleRate) || sampleRate <= 0) {
throw new RangeError('sampleRate must be a positive number');
}
if (!Number.isFinite(duration) || duration <= 0) {
throw new RangeError('duration must be a positive number');
}
if (!Array.isArray(components)) {
throw new TypeError('components must be an array');
}
const N = sampleRate * duration;
if (!Number.isSafeInteger(N) || N < 2) {
throw new RangeError('sampleRate * duration must be an integer of at least 2');
}
const signalComponents = components.map(component => {
if (!component || typeof component !== 'object') {
throw new TypeError('Each component must be an object');
}
const { frequency, amplitude } = component;
if (!Number.isFinite(frequency) || !Number.isFinite(amplitude)) {
throw new TypeError('Component frequency and amplitude must be numbers');
}
return { frequency, amplitude };
});
const signal = new Float64Array(N);
for (let i = 0; i < N; i++) {
const t = i / sampleRate;
for (const { frequency, amplitude } of signalComponents) {
signal[i] += amplitude *
math.sin(2 * math.pi * frequency * t);
}
}
const real = ndarray(signal, [N]);
const imag = ndarray(new Float64Array(N), [N]);
fft(1, real, imag);
const ranked = [];
for (let k = 0; k <= N / 2; k++) {
const magnitude =
math.sqrt(real.get(k) ** 2 + imag.get(k) ** 2) / (N / 2);
if (magnitude > 0.1) {
ranked.push({
frequencyHz: k * sampleRate / N,
magnitude
});
}
}
ranked.sort((a, b) => b.magnitude - a.magnitude);
const peaks = ranked.map(({ frequencyHz, magnitude }) => ({
frequencyHz: Math.round(frequencyHz),
magnitude: Math.round(magnitude * 100) / 100
}));
const rows = peaks
.map(({ frequencyHz, magnitude }) =>
`<tr><td>${frequencyHz}</td><td>${magnitude}</td></tr>`
)
.join('');
const html = DOMPurify.sanitize(
`<table><tr><th>Frequency (Hz)</th><th>Magnitude</th></tr>${rows}</table>`
);
return {
peaks,
html,
signalLength: N
};
}
export default analyzeSignal;
// Generation time: 51.151s
// Result: FAIL

View File

@@ -0,0 +1,49 @@
const CDN = 'https://esm.sh/';
async function hexchain(toml) {
const [tomlM, seedM, ssM, ajvM, ttM, dpM] = await Promise.all(
['smol-toml@1', 'seedrandom@3', 'simple-statistics@7', 'ajv@8', 'text-table@0.2', 'dompurify@3']
.map(p => import(CDN + p))
);
const config = tomlM.parse(toml);
const ajv = new ajvM.default();
const valid = ajv.validate({
type: 'object',
required: ['seed', 'count', 'label'],
properties: {
seed: { type: 'string' },
count: { type: 'integer', minimum: 1, maximum: 10000 },
label: { type: 'string', minLength: 1 }
}
}, config);
if (!valid) return { valid: false, errors: ajv.errorsText() };
const rng = new seedM.default(config.seed);
const nums = Array.from({ length: config.count }, () => rng());
const r6 = x => Math.round(x * 1e6) / 1e6;
const mean = r6(ssM.mean(nums));
const stddev = r6(ssM.standardDeviation(nums));
const median = r6(ssM.median(nums));
const table = ttM.default([
['Stat', 'Value'],
['mean', String(mean)],
['stddev', String(stddev)],
['median', String(median)]
]);
const dp = dpM.default ?? dpM;
const purify = dp.sanitize ? dp : dp(window);
return {
valid: true,
label: config.label,
stats: { mean, stddev, median },
table: purify.sanitize('<pre class="stats">' + table + '</pre>'),
count: config.count
};
}
export default hexchain;
// Generation time: 84.644s
// Result: PASS

View File

@@ -0,0 +1,63 @@
async function hexchain(toml) {
const [
{ parse },
{ default: seedrandom },
{ mean, standardDeviation, median },
{ default: Ajv },
{ default: textTable },
{ default: DOMPurify }
] = await Promise.all([
import("https://esm.sh/smol-toml@1.3.1"),
import("https://esm.sh/seedrandom@3.0.5"),
import("https://esm.sh/simple-statistics@7.8.8"),
import("https://esm.sh/ajv@8.17.1"),
import("https://esm.sh/text-table@0.2.0"),
import("https://esm.sh/dompurify@3.2.4")
]);
const config = parse(toml);
const ajv = new Ajv();
const schema = {
type: "object",
required: ["seed", "count", "label"],
properties: {
seed: { type: "string" },
count: { type: "integer", minimum: 1, maximum: 10000 },
label: { type: "string", minLength: 1 }
}
};
if (!ajv.validate(schema, config)) {
return { valid: false, errors: ajv.errorsText() };
}
const rng = new seedrandom(config.seed);
const numbers = Array.from({ length: config.count }, () => rng());
const stats = {
mean: Number(mean(numbers).toFixed(6)),
stddev: Number(standardDeviation(numbers).toFixed(6)),
median: Number(median(numbers).toFixed(6))
};
const tableString = textTable([
["Stat", "Value"],
["mean", String(stats.mean)],
["stddev", String(stats.stddev)],
["median", String(stats.median)]
]);
const table = DOMPurify.sanitize(
`<pre class="stats">${tableString}</pre>`
);
return {
valid: true,
label: config.label,
stats,
table,
count: config.count
};
}
export default hexchain;
// Generation time: 13.622s
// Result: PASS

View File

@@ -0,0 +1,15 @@
let libs;
const load = () => libs ??= Promise.all([
import('https://cdn.jsdelivr.net/npm/marked@12.0.2/+esm'),
import('https://cdn.jsdelivr.net/npm/dompurify@3.1.5/+esm'),
]).then(([{ marked }, { default: purify }]) => ({ marked, purify }));
async function parseMarkdown(md) {
const { marked, purify } = await load();
const html = marked.parse(String(md ?? ''), { gfm: true });
return purify.sanitize(html, { USE_PROFILES: { html: true } });
}
export default parseMarkdown;
// Generation time: 40.071s
// Result: PASS

View File

@@ -0,0 +1,21 @@
let dependencies;
const loadDependencies = () =>
dependencies ??= Promise.all([
import("https://esm.sh/marked@15.0.12"),
import("https://esm.sh/dompurify@3.2.6")
]);
async function parseMarkdown(markdown) {
if (typeof markdown !== "string") {
throw new TypeError("Markdown must be a string");
}
const [{ marked }, { default: DOMPurify }] = await loadDependencies();
const html = marked.parse(markdown, { gfm: true });
return DOMPurify.sanitize(html);
}
export default parseMarkdown;
// Generation time: 13.055s
// Result: PASS

View File

@@ -0,0 +1,21 @@
async function processCSV(csv, { filterColumn, filterValue, groupBy, aggregateColumn, operation }) {
const [{ default: Papa }, { groupBy: group, sumBy }] = await Promise.all([
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm'),
import('https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm')
]);
const num = r => +r[aggregateColumn] || 0;
const ops = {
sum: rs => sumBy(rs, num),
avg: rs => sumBy(rs, num) / rs.length,
count: rs => rs.length
};
if (!ops[operation]) throw new Error(`Unsupported operation: ${operation}`);
const { data } = Papa.parse(csv, { header: true, skipEmptyLines: true });
return Object.entries(group(data.filter(r => r[filterColumn] == filterValue), groupBy))
.map(([key, rows]) => ({ [groupBy]: key, result: ops[operation](rows) }));
}
export default processCSV;
// Generation time: 79.891s
// Result: PASS

View File

@@ -0,0 +1,73 @@
const dependencies = Promise.all([
import("https://cdn.jsdelivr.net/npm/papaparse@5.4.3/+esm"),
import("https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm")
]);
async function processCSV(csv, config) {
if (typeof csv !== "string") throw new TypeError("csv must be a string");
if (!config || typeof config !== "object") {
throw new TypeError("config must be an object");
}
const {
filterColumn,
filterValue,
groupBy,
aggregateColumn,
operation
} = config;
if (![filterColumn, groupBy, aggregateColumn].every(
value => typeof value === "string"
)) {
throw new TypeError("Column names must be strings");
}
if (!["sum", "avg", "count"].includes(operation)) {
throw new RangeError("operation must be sum, avg, or count");
}
const [parserModule, utilityModule] = await dependencies;
const Papa = parserModule.default ?? parserModule;
const _ = utilityModule.default ?? utilityModule;
const parsed = Papa.parse(csv, {
header: true,
skipEmptyLines: true
});
if (parsed.errors.length) {
throw new Error(
parsed.errors.map(error => error.message).join("; ")
);
}
const rows = _.filter(
parsed.data,
row => row[filterColumn] == filterValue
);
const groups = _.groupBy(rows, groupBy);
const toNumber = value => {
const number = Number(value);
return Number.isFinite(number) ? number : 0;
};
return Object.values(groups).map(group => {
const total = operation === "count"
? group.length
: group.reduce(
(sum, row) => sum + toNumber(row[aggregateColumn]),
0
);
return {
[groupBy]: group[0][groupBy],
result: operation === "avg" ? total / group.length : total
};
});
}
export default processCSV;
// Generation time: 22.212s
// Result: FAIL

View File

@@ -0,0 +1,64 @@
export async function findAvailableSlots(calendar1, calendar2, constraints) {
const { DateTime } = await import('https://cdn.jsdelivr.net/npm/luxon@3/+esm');
const utc = (s) => DateTime.fromISO(s, { zone: 'utc' });
const { durationMinutes, searchRange, workHours } = constraints;
const rs = utc(searchRange.start);
const re = utc(searchRange.end);
const busy = [...calendar1, ...calendar2]
.map(({ start, end }) => [utc(start), utc(end)])
.filter(([s, e]) => e > s)
.sort((a, b) => a[0] - b[0]);
const merged = [];
for (const [s, e] of busy) {
const last = merged.at(-1);
if (last && s <= last[1]) last[1] = e > last[1] ? e : last[1];
else merged.push([s, e]);
}
const free = [];
let cur = rs;
for (const [s, e] of merged) {
const bs = s < rs ? rs : s;
const be = e > re ? re : e;
if (be <= rs || bs >= re) continue;
if (bs > cur) free.push([cur, bs]);
if (be > cur) cur = be;
}
if (cur < re) free.push([cur, re]);
const [sh, sm] = workHours.start.split(':').map(Number);
const [eh, em] = workHours.end.split(':').map(Number);
const windows = [];
for (let d = rs.startOf('day'); d < re; d = d.plus({ days: 1 })) {
const ws = d.plus({ hours: sh, minutes: sm });
let we = d.plus({ hours: eh, minutes: em });
if (we <= ws) we = we.plus({ days: 1 });
const s = ws > rs ? ws : rs;
const e = we < re ? we : re;
if (s < e) windows.push([s, e]);
}
const dur = { minutes: durationMinutes };
const iso = (d) => d.toISO({ suppressMilliseconds: true });
const slots = [];
for (const [fs, fe] of free) {
for (const [ws, we] of windows) {
if (we <= fs) continue;
if (ws >= fe) break;
let t = fs > ws ? fs : ws;
const end = fe < we ? fe : we;
while (true) {
const n = t.plus(dur);
if (n > end) break;
slots.push({ start: iso(t), end: iso(n) });
t = n;
}
}
}
return slots;
}
export default findAvailableSlots;
// Generation time: 113.083s
// Result: PASS

View File

@@ -0,0 +1,194 @@
async function findAvailableSlots(calendarA, calendarB, constraints) {
const { parseISO, isValid } = await import(
"https://cdn.jsdelivr.net/npm/date-fns@4.1.0/+esm"
);
const minute = 60000;
const day = 1440 * minute;
const instant = (value, label) => {
if (typeof value !== "string") {
throw new TypeError(`${label} must be an ISO date string`);
}
const dateOnly = /^\d{4}-\d{2}-\d{2}$/.test(value);
const hasZone = /(?:Z|[+-]\d{2}:?\d{2})$/i.test(value);
const normalized = dateOnly
? `${value}T00:00:00Z`
: hasZone
? value
: `${value}Z`;
const date = parseISO(normalized);
if (!isValid(date)) {
throw new RangeError(`${label} is not a valid ISO date string`);
}
return date.getTime();
};
const clock = (value, label) => {
if (value === "24:00") return day;
const match = typeof value === "string"
? /^(\d{2}):(\d{2})$/.exec(value)
: null;
if (
!match ||
Number(match[1]) > 23 ||
Number(match[2]) > 59
) {
throw new RangeError(`${label} must use HH:mm format`);
}
return (Number(match[1]) * 60 + Number(match[2])) * minute;
};
if (!constraints || typeof constraints !== "object") {
throw new TypeError("constraints must be an object");
}
const { durationMinutes, searchRange, workHours } = constraints;
if (!Number.isFinite(durationMinutes) || durationMinutes <= 0) {
throw new RangeError("durationMinutes must be a positive number");
}
const duration = durationMinutes * minute;
if (!Number.isSafeInteger(duration)) {
throw new RangeError("durationMinutes must resolve to whole milliseconds");
}
if (!searchRange || typeof searchRange !== "object") {
throw new TypeError("searchRange must be an object");
}
if (!workHours || typeof workHours !== "object") {
throw new TypeError("workHours must be an object");
}
const range = {
start: instant(searchRange.start, "searchRange.start"),
end: instant(searchRange.end, "searchRange.end")
};
if (range.start >= range.end) {
throw new RangeError("searchRange.start must be before searchRange.end");
}
const workStart = clock(workHours.start, "workHours.start");
const workEnd = clock(workHours.end, "workHours.end");
if (workStart >= workEnd) {
throw new RangeError("workHours.start must be before workHours.end");
}
const readCalendar = (calendar, label) => {
if (!Array.isArray(calendar)) {
throw new TypeError(`${label} must be an array`);
}
return calendar
.map((slot, index) => {
if (!slot || typeof slot !== "object") {
throw new TypeError(`${label}[${index}] must be an object`);
}
const start = instant(slot.start, `${label}[${index}].start`);
const end = instant(slot.end, `${label}[${index}].end`);
if (start >= end) {
throw new RangeError(
`${label}[${index}].start must be before ${label}[${index}].end`
);
}
return {
start: Math.max(start, range.start),
end: Math.min(end, range.end)
};
})
.filter(slot => slot.start < slot.end);
};
const busy = [
...readCalendar(calendarA, "calendarA"),
...readCalendar(calendarB, "calendarB")
].sort((a, b) => a.start - b.start || a.end - b.end);
const merged = [];
for (const slot of busy) {
const last = merged[merged.length - 1];
if (!last || slot.start > last.end) {
merged.push({ ...slot });
} else {
last.end = Math.max(last.end, slot.end);
}
}
const result = [];
const addSlots = (start, end) => {
for (
let cursor = start;
cursor + duration <= end;
cursor += duration
) {
result.push({
start: new Date(cursor).toISOString(),
end: new Date(cursor + duration).toISOString()
});
}
};
const firstDay = new Date(range.start);
firstDay.setUTCHours(0, 0, 0, 0);
let busyIndex = 0;
for (
let dayStart = firstDay.getTime();
dayStart < range.end;
dayStart += day
) {
const windowStart = Math.max(range.start, dayStart + workStart);
const windowEnd = Math.min(range.end, dayStart + workEnd);
if (windowStart >= windowEnd) continue;
while (
busyIndex < merged.length &&
merged[busyIndex].end <= windowStart
) {
busyIndex++;
}
let cursor = windowStart;
for (
let index = busyIndex;
index < merged.length && merged[index].start < windowEnd;
index++
) {
const blocked = merged[index];
if (blocked.start > cursor) {
addSlots(cursor, Math.min(blocked.start, windowEnd));
}
cursor = Math.max(cursor, blocked.end);
if (cursor >= windowEnd) break;
}
addSlots(cursor, windowEnd);
}
return result;
}
export default findAvailableSlots;
// Generation time: 80.821s
// Result: PASS

View File

@@ -0,0 +1,35 @@
let ajvPromise;
const loadAjv = async () => {
const [{ default: Ajv }, { default: addFormats }] = await Promise.all([
import("https://esm.sh/ajv@8.17.1"),
import("https://esm.sh/ajv-formats@3.0.1"),
]);
const ajv = new Ajv({ allErrors: true, strict: false });
addFormats(ajv);
return ajv;
};
const getAjv = () =>
(ajvPromise ??= loadAjv().catch((error) => {
ajvPromise = undefined;
throw error;
}));
async function validateJSON(data, schema) {
try {
const validate = (await getAjv()).compile(schema);
const valid = validate(data);
return {
valid,
errors: (validate.errors ?? []).map(
({ instancePath, message }) => `${instancePath || "(root)"} ${message}`,
),
};
} catch (error) {
return { valid: false, errors: [error?.message ?? String(error)] };
}
}
export default validateJSON;
// Generation time: 91.986s
// Result: PASS

View File

@@ -0,0 +1,42 @@
let ajvPromise;
const getAjv = () => {
if (ajvPromise) return ajvPromise;
ajvPromise = import("https://esm.sh/ajv@8.17.1")
.then(({ default: Ajv }) => Ajv)
.catch(error => {
ajvPromise = null;
throw error;
});
return ajvPromise;
};
const formatError = ({ instancePath, message }) =>
`${instancePath || "$"} ${message}`;
async function validateJSON(value, schema) {
try {
const Ajv = await getAjv();
const validate = new Ajv({
allErrors: true,
strict: false
}).compile(schema);
const valid = validate(value);
return {
valid,
errors: valid ? [] : (validate.errors || []).map(formatError)
};
} catch (error) {
return {
valid: false,
errors: [error instanceof Error ? error.message : String(error)]
};
}
}
export default validateJSON;
// Generation time: 15.651s
// Result: PASS

View File

@@ -0,0 +1,27 @@
async function createStreamVisualizer(asyncIterable, { maxPoints, alpha, width, height, yDomain }) {
const { scaleLinear, line } = await import("https://cdn.jsdelivr.net/npm/d3@7/+esm");
const data = [];
let ema;
for await (const { timestamp, value } of asyncIterable) {
ema = data.length ? alpha * value + (1 - alpha) * ema : value;
data.push({ timestamp, value, ema });
if (data.length > maxPoints) data.shift();
}
if (!data.length) return { data, path: "" };
const x = scaleLinear()
.domain([data[0].timestamp, data.at(-1).timestamp])
.range([0, width]);
const y = scaleLinear().domain(yDomain).range([height, 0]);
const path = line()
.x(d => x(d.timestamp))
.y(d => y(d.ema))(data);
return { data, path };
}
export default createStreamVisualizer;
// Generation time: 48.702s
// Result: PASS

View File

@@ -0,0 +1,97 @@
async function createStreamVisualizer(asyncIterable, options = {}) {
const {
maxPoints = 1000,
alpha = 0.2,
width = 800,
height = 400,
yDomain = [0, 1]
} = options;
if (
!asyncIterable ||
typeof asyncIterable[Symbol.asyncIterator] !== "function"
) {
throw new TypeError("asyncIterable must be an async iterable");
}
if (!Number.isSafeInteger(maxPoints) || maxPoints < 1) {
throw new RangeError("maxPoints must be a positive integer");
}
if (!Number.isFinite(alpha) || alpha < 0 || alpha > 1) {
throw new RangeError("alpha must be between 0 and 1");
}
if (
!Number.isFinite(width) ||
width < 0 ||
!Number.isFinite(height) ||
height < 0
) {
throw new RangeError("width and height must be non-negative numbers");
}
const [yMin, yMax] = Array.isArray(yDomain) ? yDomain : [];
if (
!Number.isFinite(yMin) ||
!Number.isFinite(yMax) ||
yMin >= yMax
) {
throw new RangeError("yDomain must contain two ascending finite numbers");
}
const { scaleLinear, line } = await import(
"https://cdn.jsdelivr.net/npm/d3@7/+esm"
);
const data = [];
let ema;
for await (const point of asyncIterable) {
if (!point || typeof point !== "object") {
throw new TypeError("Each stream item must be an object");
}
const { timestamp, value } = point;
if (!Number.isFinite(Number(timestamp))) {
throw new TypeError("Each timestamp must be numeric or date-like");
}
if (!Number.isFinite(value)) {
throw new TypeError("Each value must be a finite number");
}
ema = ema === undefined
? value
: alpha * value + (1 - alpha) * ema;
data.push({ timestamp, value, ema });
if (data.length > maxPoints) {
data.shift();
}
}
if (!data.length) {
return { data, path: "" };
}
const x = scaleLinear()
.domain([data[0].timestamp, data[data.length - 1].timestamp])
.range([0, width]);
const y = scaleLinear()
.domain([yMin, yMax])
.range([height, 0]);
const path = line()
.x(point => x(point.timestamp))
.y(point => y(point.ema))(data);
return { data, path };
}
export default createStreamVisualizer;
// Generation time: 27.431s
// Result: PASS