1. /**
  2. * Parses task queue data for manual execution.
  3. * Supports older JavaScript versions (ES5).
  4. *
  5. * @param {Array<Object>} taskQueue - An array of task objects.
  6. * Each task object should have at least a 'name' property.
  7. * Optionally, it can have other properties like 'description', 'priority', etc.
  8. * @returns {Array<Object>} - An array of task objects suitable for manual execution.
  9. */
  10. function parseTaskQueue(taskQueue) {
  11. if (!Array.isArray(taskQueue)) {
  12. console.error("Invalid input: taskQueue must be an array.");
  13. return [];
  14. }
  15. const manualTasks = [];
  16. for (let i = 0; i < taskQueue.length; i++) {
  17. const task = taskQueue[i];
  18. if (typeof task !== 'object' || task === null) {
  19. console.warn("Skipping invalid task object at index", i);
  20. continue; // Skip non-object tasks
  21. }
  22. if (typeof task.name !== 'string' || task.name.trim() === '') {
  23. console.warn("Skipping task with missing or empty name at index", i);
  24. continue; // Skip tasks without a name
  25. }
  26. // Create a copy of the task to avoid modifying the original
  27. const manualTask = { ...task };
  28. manualTasks.push(manualTask);
  29. }
  30. return manualTasks;
  31. }

Add your comment