function formatUserRecords(records) {
if (!records || records.length === 0) {
return "No records provided.";
}
let output = "";
const maxAge = 65;
const minScore = 50;
const maxTransactions = 10;
for (let i = 0; i < records.length; i++) {
const record = records[i];
if (!record) continue; // Skip null or undefined records
const age = record.age;
const score = record.score;
const transactions = record.transactions;
let formattedRecord = `Record ${i + 1}: `;
if (age > maxAge) {
formattedRecord += `Age (${age}) exceeds the limit (${maxAge}). `;
} else if (age < 18) {
formattedRecord += `Age (${age}) is below the minimum age (18). `;
}
if (score < minScore) {
formattedRecord += `Score (${score}) is below the minimum score (${minScore}). `;
}
if (transactions > maxTransactions) {
formattedRecord += `Transactions (${transactions}) exceeds the limit (${maxTransactions}). `;
}
output += formattedRecord + "\n";
}
return output;
}
Add your comment