根据给定示例与反例审查生成实现。
从客户数组导出新的行对象;接受命名选项 { includeInactive },默认值为 false;保留零余额;只包含 id、balance 和已有的 active 或 inactive 状态;拒绝其他或缺失状态;绝不暴露邮箱地址。
JavaScript
function exportCustomerRows(customers, includeInactive = false) {
if (!Array.isArray(customers)) {
throw new TypeError("customers must be an array");
}
const rows = [];
for (const customer of customers) {
if (!customer.balance) continue;
if (!includeInactive && customer.status === "inactive") continue;
rows.push({
id: customer.id,
email: customer.email,
balance: Math.round(customer.balance),
status: customer.status || "active",
});
}
return rows;
}
生成代码仅作示例,不代表任何特定模型