I am getting different results using JS filter
and some
methods when running within my node js app (server side) and in the browser console (client side)
I have the following 2 arrays of objects, and what I want to achieve is to create a new array of objects that does not include anything that is duplicated
export default async (req, res) => {
const userAlerts = req.body;
console.log(userAlerts);
userAlerts = [ {
user_id: 232,
match_id: 3918053,
alert_type: 'OVER0.5FHCORNERS',
alert_odds: '2.0',
home_team: 'Pescara U19',
},
{ user_id: 232,
match_id: 3909005,
alert_type: 'OVER0.5FHCORNERS',
alert_odds: '2.0',
home_team: 'Fortuna Koln U19',
}
]
const existingAlerts = await queries.getUserTelegramAlerts(userID);
console.log(existingAlerts);
existingAlerts = [ {
user_id: 232,
match_id: 3918053,
alert_type: 'OVER0.5FHCORNERS',
alert_odds: '2.0',
home_team: 'Pescara U19',
},
{
user_id: 232,
match_id: 3909005,
alert_type: 'OVER0.5FHCORNERS',
alert_odds: '2.0',
home_team: 'Fortuna Koln U19',
}
]
const alertsToSet = userAlerts.filter(x => {
return !existingAlerts.some(
t =>
t.user_id === x.user_id &&
t.match_id === x.match_id &&
t.alert_type === x.alert_type &&
t.alert_odds === x.alert_odds
);
});
console.log({ alertsToSet });
}
Logging out alertsToSet
in the browser is empty, which is the desired behaviour, but when running this code server side, alertsToSet
has 2 objects
Am i missing something or made a mistake ?