Smartest way to filter a list using a different list

Viewed 16

I have two lists. One of them is essentially representing keys (dates), the other the values. I really just need the values themselves, but I want to get all values that lie between two dates. And optimally, I'd also like to use a certain sampling frequency to, say, get the values for all first days of the week between my two dates (ie sampling every 7th day).

I can easily filter my dates between two dates by calling .filter(e => e > start && e < end), and combine it with my prices array into its own object and then mapping it or something.

But since I'll be running this on large datasets in AWS, I'd need to be quite efficient with the way I do this. What would be the computationally least expensive algorithm to achieve what I want?

The best way would probably be a simple for loop, or actually, probably a binary search, but is there a less ugly way of doing it? I really enjoy chaining stream operations.

0 Answers
Related