So I want to use Array.prototype.reduce function to reduce some array (converted from object).
This is the object which I'll later use Object.entries to get the array.
const activityLoading = {
topicsForClassCourse: true,
b: false,
c: false,
d: true,
e: false
}
I also have an array of keys that I want to ignore while reducing this object. So any key that are in activityLoading as well as local it will be neglected.
const local = [ "topicsForClassCourse", "e" ]
Now I want to reduce the object into a single value. If any key is true except the one in the local array, it should return true, else false.
This is what I could come up with. But it's returning false.
const loadingSome = () => {
const local = [ "topicsForClassCourse", "timetableForClass" ];
const entries = Object.entries(activityLoading)
const reducer = (acc, current) => {
if(local.includes(current[0])) {
return false
}
if(current[1]) {
return true;
}
return false
}
const result = entries.reduce(reducer, false)
console.log(result)
}