/**
* Filters an array of timestamps to include only those within a specified range.
*
* @param {Array<number>} timestamps An array of timestamp values (in milliseconds).
* @param {number} startTime The start of the desired time range (in milliseconds).
* @param {number} endTime The end of the desired time range (in milliseconds).
* @returns {Array<number>} A new array containing only the timestamps within the range.
*/
function filterTimestamps(timestamps, startTime, endTime) {
if (!Array.isArray(timestamps)) {
return []; //Return empty array if input is not an array
}
const filteredTimestamps = [];
for (let i = 0; i < timestamps.length; i++) {
const timestamp = timestamps[i];
if (typeof timestamp === 'number' && timestamp >= startTime && timestamp <= endTime) {
filteredTimestamps.push(timestamp);
}
}
return filteredTimestamps;
}
Add your comment