Skip to content
Advertisement

How to filter one array with another array values and return a key value of the first array

I have 2 arrays with current week dates and investments with value and date. I want to return an array with the values that have corresponding dates between the 2 arrays.

My non-working solution is:

JavaScript

When what I need is: [0.77, 1.50, 0.80, 1.00, 0.77, 0.79]

Probably the filter inside the map is not the best option as it´s going to return the value of the first array (which is a date).

I also have the problem that result returns also the undefined. I then run filteredResult to remove all the undefined in the result. I guess this is a job that can be done with one function all together.

Advertisement

Answer

Take it step by step:

  1. Filter investmentsData on whether or not daysOfWeek contains the date
  2. From the filtered values, return the value.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement