1. /**
  2. * Filters an array of timestamps to include only those within a specified range.
  3. *
  4. * @param {Array<number>} timestamps An array of timestamp values (in milliseconds).
  5. * @param {number} startTime The start of the desired time range (in milliseconds).
  6. * @param {number} endTime The end of the desired time range (in milliseconds).
  7. * @returns {Array<number>} A new array containing only the timestamps within the range.
  8. */
  9. function filterTimestamps(timestamps, startTime, endTime) {
  10. if (!Array.isArray(timestamps)) {
  11. return []; //Return empty array if input is not an array
  12. }
  13. const filteredTimestamps = [];
  14. for (let i = 0; i < timestamps.length; i++) {
  15. const timestamp = timestamps[i];
  16. if (typeof timestamp === 'number' && timestamp >= startTime && timestamp <= endTime) {
  17. filteredTimestamps.push(timestamp);
  18. }
  19. }
  20. return filteredTimestamps;
  21. }

Add your comment