I am trying to run a series of keywords against a series of categories and then within those categories there are some options. So I have ended up doing a map over map over a reduce and when dealing with a lot of entries node consumes way too much memory.
I got this, what it does is not really the problem, but how to make it not crave for such amounts of memory?
const keywords = [
{
Keyword: 'foo',
URL: 'https://www.facebook.co.uk'
},
{
Keyword: 'foo',
URL: 'https://www.twitter.co.uk/blue'
},
{
Keyword: 'faa',
URL: 'https://www.facebook.co.uk/twitter'
},
{
Keyword: 'faa',
URL: 'https://www.apple.co.uk/green'
}
]
const categories = [
{
name: 'Tech',
options: [
{
method: 'include',
regex: 'facebook'
},
{
method: 'exclude',
regex: 'twitter'
}
]
},
{
name: 'Green',
options: [
{
method: 'include',
regex: 'green'
}
]
}
]
const result = keywords.map((obj) => {
categories.map(({ name, options }) => {
const option = options.reduce((acc, { method, regex }) => {
acc.push(method === 'include' ? obj.URL.includes(regex) : !obj.URL.includes(regex))
return acc
}, [])
obj[name] = !option.includes(false)
})
return obj
})
console.log(result)
.as-console-wrapper { max-height: 100% !important; top: 0; }
map(), so it should beforEach().