I'm having trouble figuring out why this function throws an error when it reaches the 'includes'
method, when console logging whitelist, it shows that it is an array, when i use the includes method, it is throwing an error, cannot read property includes of undefined
const test = (body, ...whitelists) => {
const bodies = whitelists.map(({ type = null, whitelist }) => {
console.log('whitelist ', whitelist)
const whitelistedBody = Object.entries(body).reduce(
(newBody, [key, value]) => {
console.log('KEY ', key)
console.log('whitelist ', whitelists)
if (whitelist.includes(key)) {
newBody[key] = value;
}
console.log('newBody ', newBody)
return newBody;
},
{}
);
return { type, body: whitelistedBody };
});
return (
bodies.find(({ body }) => Object.keys(body).length) || {
body: {},
type: null,
}
);
};
test({firstKey: '123'}, ['firstKey']);