function compactLog(records, indent = 0) {
if (!records || records.length === 0) {
console.log("No records to log.");
return;
}
for (let i = 0; i < records.length; i++) {
const record = records[i];
const indentStr = " ".repeat(indent); // Indentation for readability
//Handle different data types for concise output
if (typeof record === 'object' && record !== null) {
console.log(`${indentStr}Record: {`);
for (const key in record) {
if (record.hasOwnProperty(key)) {
let value = record[key];
if (typeof value === 'string') {
value = `"${value}"`; //Quote strings
}
console.log(`${indentStr} ${key}: ${value}`);
}
}
console.log(`${indentStr} }`);
} else {
console.log(`${indentStr}Record: ${record}`); //Simple output for primitives
}
}
}
Add your comment