1. function compactLog(records, indent = 0) {
  2. if (!records || records.length === 0) {
  3. console.log("No records to log.");
  4. return;
  5. }
  6. for (let i = 0; i < records.length; i++) {
  7. const record = records[i];
  8. const indentStr = " ".repeat(indent); // Indentation for readability
  9. //Handle different data types for concise output
  10. if (typeof record === 'object' && record !== null) {
  11. console.log(`${indentStr}Record: {`);
  12. for (const key in record) {
  13. if (record.hasOwnProperty(key)) {
  14. let value = record[key];
  15. if (typeof value === 'string') {
  16. value = `"${value}"`; //Quote strings
  17. }
  18. console.log(`${indentStr} ${key}: ${value}`);
  19. }
  20. }
  21. console.log(`${indentStr} }`);
  22. } else {
  23. console.log(`${indentStr}Record: ${record}`); //Simple output for primitives
  24. }
  25. }
  26. }

Add your comment