Instead of doing a nested conditional, is there a cleaner more efficient way of achieving this:
- if option === 3, add both the nearbyLocations and recentSearches object to array
- if option == 1, add only the recentSearches
- else (or option === 2), add only nearbyLocations object
See below for my code. Thank you!
const results = option === 3 ? [...state.nearbyLocations, ...recentSearches] : option === 1 ? [...recentSearches] : [...state.nearbyLocations]