You can just use a simple loop for this:
function arraysIntersect(arr1, arr2) {
for (var i = 0; i < arr1.length; ++i) {
if (arr2.includes(arr1[i])) return true;
}
return false;
}
I assume state.checkedIds
is an array. If that's true, your code doesn't work because you are checking whether your filtered and mapped todos include checkedIds
(which it doesn't) instead of checking whether it includes any of the elements of the array checkedIds
(which it might).
You can use my code like this:
var doneTodoIds = todos.filter(todo => todo.completed === true ).map( todo => todo.id).includes(this.state.checkedIds);
var result = arraysIntersect(doneTodoIds, this.state.checkedIds);
You could also solve this with a higher level data structure (Alejandro's suggestion), but that might not be necessary (depending on the context of your code fragment).