I have this array of dates.
const dateArray = ["7/12/2021","7/13/2021","7/14/2021","7/15/2021"]
and I am trying to see if any of these dates appear inside my other array of array of objects, those dates will match something inside the objects.
const data = [
[ { id: 1, date: "7/13/2021" }, { id:2, date: "7/15/2021" } ],
[ { id: 1, date: "7/14/2021" }, { id:2, date: "7/15/2021" } ],
]
so if date doesn't match I want to return 0 for that date. something like this
const result = [
[0, 1, 0, 1],
[0, 0, 1, 1]
]
I tried something like this.....
var getResult = (dateArray, data) => {
const result = []
let index = 0;
for (let i = 0; i < dateArray.length; i++) {
for (let j = 0; j < data.length; j++) {
let count = 0
if (dateArray[i] === data[j][index].date) {
count++
index++
if (index === data[i].length) {
return
}
}
result.push(count)
}
}
console.log(result)
}
but it doesn't work of course.... Thank you for your help!