Skip to content
Advertisement

I need to minus one key, of array of objects, from another key of another array of objects

I have next two arrays:

JavaScript

if startDate is between startDay and endDay, I have to minus firstArray number and secondArray number creating new key with result

As result, I have to put new key in firstArray with result:

JavaScript

if I have more than one startDate in the same range(between startDay and endDay) I have to add to the last result of that range

The code I have for now:

JavaScript

Advertisement

Answer

Map won’t work too well for looping through two arrays and changing values.

Just use a simple for loop, check your conditions between firstArray[i] and secondArray[i], then add the value to firstArray[i].result

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