Using .map(), .reduce(), .filter() functions, how can I write an efficient routine that can derive all Radio stations that have a .genre that exists in the Popular genres set AND a .tag in the Tags set?
// Radio stations
const stations = [
{
title: 'BBC Radio 1',
genre:['Popular', 'Rnb', 'Hip Hop', 'Dance'],
tag: ['bbc', 'radio 1', 'uk']
},
{
title: 'Classic FM',
genre:['Classical', 'Orchestra'],
tag: ['bbc', 'uk']
},
]
// Popular genres
const popular = [
'Popular',
'House',
'Chillout',
'Top 40',
'Drum And Bass'
]
// Tags
const tags = [
'bbc',
'uk'
]
I believe that this is a common pattern which doesn't seem to be well documented. My own attempts have involved writing nested loops which I believe could be cleaner. My dataset contains ~22,000 entries (I can tweak this to performance), and searches upon key press. This will run offline and I cannot use a database, even a local one. I would like to use the; .map(), .reduce(), .filter() functions, even though I understand that these may impose function call overhead and that I could use a binary tree.
map/reduce/filterwill not optimise anything (apart maybe from readability), you need a different data structure for that.