I am trying to figure out how to compare two arrays to determine if there are any duplicates within them.
const result = this.specialRange.filter(d => !dayMonth.includes(d));
What I have attempted so far just returns the entire array back to me, but I only want to know if there is a duplicate: yes -> do something, no -> don't do anything.
var dayMonth: any[] = ["1201","1202","1203","1204","1205"];
specialRange: any[] = ["1201","1202","1203","1204"];
Depending on the leading argument, it either returns the entire special range or dayMonth, but I simply want a true/false result if there is a duplicate.
Both arrays have similar values, even though they are of type Any. This is just for practical learning purposes at the moment.
The values always follow a format like "1201,1202,1203,1204" representing MM/DD.
Update for Pyth:
When testing:
dayMonth = 1215,1216
specialRange =
1215,1216,1217,1218,1219,1220,1221,1222,1223,1224,1225,1226,1227,1228,1229
Modified method:
for(let v of dayMonth){
if(this.specialRange.includes(v)){
alert('true');
}
else{
alert('false')
}
}
Result => False/False
For some reason, my console does not log anything when I use console.log.