Skip to content
Advertisement

How to merge two multidimensional arrays and adjust existing values?

I would like to put together the following arrays and calculate best prices.

JavaScript
JavaScript

How can I combine these 2 arrays to achieve the following result?

JavaScript

Can anyone help me?

Advertisement

Answer

One way to do it is to find the element whose from value is greater than pricesForAllCustomer to value and place it between these elements (assuming that customerSpecificPrices is already ordered.):

JavaScript

The result will be:

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