My objects can have one or more properties assigned, with a total of 5 different properties in my case.
To illustrate this, let's use a simple movie example where each movie can be assigned from 5 different genres.
I have come up with two methods to approach this:
- Assign a boolean for each property of every object individually OR
- Create an array containing the list of assigned properties for each object
Here are the options:
Option 1:
[{id: 1, name: 'some movie 1', comedy: true, thriller: true, drama: true, action: false, adventure: true},
{id: 2, name: 'some movie 2', comedy: false, thriller: true, drama: false, action: false, adventure: false},
{id: 3, name: 'some movie 3', comedy: true, thriller: true, drama: true, action: false, adventure: true},
{id: 4, name: 'some movie 4', comedy: true, thriller: true, drama: true, action: false, adventure: false}, ...]
Option 2:
[{id: 1, name: 'some movie 1', genre: ['comedy','thriller','drama']},
{id: 2, name: 'some movie 2', genre: ['thriller','drama']},
{id: 3, name: 'some movie 3', genre: ['comedy','thriller','adventure']},
{id: 4, name: 'some movie 4', genre: ['comedy','thriller']}, ...]
Personally, I prefer option 2 as it is more concise and does not store redundant data (false boolean values).
However, I am concerned about the performance implications. Using .include() to check arrays seems slower compared to a simple boolean check as seen in option 1.
This leads me to a dilemma between redundancy and performance. Is there a better solution that could address this issue like using a different data structure?
Thank you in advance!