1. function formatUserRecords(records) {
  2. if (!records || records.length === 0) {
  3. return "No records provided.";
  4. }
  5. let output = "";
  6. const maxAge = 65;
  7. const minScore = 50;
  8. const maxTransactions = 10;
  9. for (let i = 0; i < records.length; i++) {
  10. const record = records[i];
  11. if (!record) continue; // Skip null or undefined records
  12. const age = record.age;
  13. const score = record.score;
  14. const transactions = record.transactions;
  15. let formattedRecord = `Record ${i + 1}: `;
  16. if (age > maxAge) {
  17. formattedRecord += `Age (${age}) exceeds the limit (${maxAge}). `;
  18. } else if (age < 18) {
  19. formattedRecord += `Age (${age}) is below the minimum age (18). `;
  20. }
  21. if (score < minScore) {
  22. formattedRecord += `Score (${score}) is below the minimum score (${minScore}). `;
  23. }
  24. if (transactions > maxTransactions) {
  25. formattedRecord += `Transactions (${transactions}) exceeds the limit (${maxTransactions}). `;
  26. }
  27. output += formattedRecord + "\n";
  28. }
  29. return output;
  30. }

Add your comment