1. function exportTimestampsWithErrors(data) {
  2. if (!Array.isArray(data)) {
  3. console.error("Input must be an array.");
  4. return [];
  5. }
  6. const results = [];
  7. for (let i = 0; i < data.length; i++) {
  8. const item = data[i];
  9. if (typeof item !== 'object' || item === null) {
  10. console.error(`Element at index ${i} is not a valid object. Skipping.`);
  11. results.push({ timestamp: null, error: "Invalid object format" });
  12. continue;
  13. }
  14. if (!item.timestamp) {
  15. console.error(`Element at index ${i} is missing 'timestamp' property.`);
  16. results.push({ timestamp: null, error: "Missing 'timestamp' property" });
  17. continue;
  18. }
  19. if (typeof item.timestamp !== 'number') {
  20. console.error(`Element at index ${i} has invalid 'timestamp' type. Expected number.`);
  21. results.push({ timestamp: null, error: "Invalid 'timestamp' type. Expected number." });
  22. continue;
  23. }
  24. results.push({ timestamp: item.timestamp, error: null });
  25. }
  26. return results;
  27. }

Add your comment