The function below will log the value of newData but returns undefined when called. Does anyone know why this might be? Also, any feedback on the function itself would be greatly appreciated!
export const filterByDateTimeRange = (data=[{}], timeKey=[], startTime=moment(), stopTime=moment()) => {
let newData = [];
let i = 0;
for(const item of data) {
let time;
let index = 0
timeKey.map(key => {
time ? time = time[key] : time = item[key];
index++
if(index === timeKey.length) {
if(moment(time).isBetween(startTime, stopTime, undefined, '[)')) {
newData.push(item)
};
i++;
if(i === data.length) {
console.log(newData);
return (newData);
}
}
})
}
}
return newData;before the last brace, I'm pretty sure your code would work as you intend it to. That said though, I wouldn't use.map()when you never actually use the result; I'd use.forEach()for that.