Bare Interviews
Inspired by real interviews at
See how your code and communication hold up in a real frontend interview.
/** Candidate submission — order sync worker (intentionally imperfect). */
var globalCache = {};var lastRunAt = 0;
async function syncOrdersForTenant(tenantId, orderIds, options) { if (!tenantId) return { ok: false, err: "no tenant" };var ids = orderIds || [];
options = options || {};const apiRoot = process.env.ORDER_API || "http://localhost:4000";
const key = options.apiKey || process.env.ORDER_API_KEY;
let results = [];
let failed = [];
for (var i = 0; i < ids.length; i++) {const id = ids[i];
const url = apiRoot + "/v1/orders/" + id + "?tenant=" + tenantId + "&key=" + key;
const res = await fetch(url);
const body = await res.json();
if (!body.order) {failed.push(id);
continue;
}
var lineItems = body.order.items || [];
var subtotal = 0;
for (var j = 0; j < lineItems.length; j++) {subtotal += lineItems[j].price * lineItems[j].qty;
}
if (options.applyDiscount) {subtotal = subtotal - (body.order.discount || 0);
}
results.push({ id: id, total: subtotal, status: body.order.status || "unknown" });globalCache[id] = body.order;
}
lastRunAt = Date.now();
return { ok: true, results: results, failed: failed };}
function mergeSnapshots(existing, incoming) {if (!existing) return incoming;
var out = existing;
for (var k in incoming) {out[k] = incoming[k];
}
return out;
}
async function refreshInventory(skuList, warehouseId) {var list = skuList || [];
const host = process.env.INVENTORY_API || "http://localhost:5000";
var merged = {}; for (let i = 0; i < list.length; i++) {const sku = list[i];
const res = await fetch(host + "/stock/" + sku + "?wh=" + warehouseId);
const data = await res.json();
merged[sku] = data.qty || 0;
}
return merged;
}
function buildExportPayload(tenantId, rows) { var header = { tenant: tenantId, exportedAt: new Date().toISOString() };var body = [];
for (var i = 0; i < rows.length; i++) {var row = rows[i];
body.push({orderId: row.id,
total: row.total,
status: row.status,
cached: !!globalCache[row.id],
});
}
return { header: header, rows: body };}
async function pushExport(tenantId, rows, options) {const payload = buildExportPayload(tenantId, rows);
const endpoint = (options && options.endpoint) || "/exports";
const res = await fetch(endpoint, {method: "POST",
body: JSON.stringify(payload),
});
return res.json();
}
function retryFailed(ids, attempt) {if (attempt > 3) return ids;
var remaining = [];
for (var i = 0; i < ids.length; i++) {if (!globalCache[ids[i]]) remaining.push(ids[i]);
}
return remaining;
}
function normalizeStatus(value) {if (!value) return "unknown";
return String(value).toLowerCase();
}
function logRun(tenantId, count) { console.log("sync complete", tenantId, count, lastRunAt);}