Let's say I have two array pairs:
let a1 = [2000, 4000, 6000, 8000, 10000, 12000],
b1 = [2000, 4000, 6000, 8000, 10000, 12000, 14000];
and
let a2 = [10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000],
b2 = [10000, 20000, 30000, 40000, 50000, 60000];
or any arbitrary pair of integers.
The task is to expand the smallest array in the pair to largest size in this way, keeping smallest domain the same as well as values:
b1 = [2000, 4000, 6000, 8000, 10000, 12000, 14000];
expanded_a1 = [2000, 4000, 6000, 8000, 10000, 12000, 12000];
a2 = [10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000]
expanded_b2 = [10000, 20000, 20000, 30000, 30000, 40000, 40000, 50000, 50000, 60000];
invalid_expanded_b2 = [10000, 15000, 20000, 30000, 30000, 40000, 40000, 50000, 50000, 60000];
//second value is invalid
And once again, example with the third pair:
let a3 = [10, 15, 20, 25, 30, 35];
let b3 = [10, 20, 30];
So, expanded b3 should have only 10,20,30 values and its domain have to be [10,30]
[10, 15, 20, 25, 30, 35]
↓ ↓ ↓ ↓ ↓ ↓
expanded_b3 = [10, 20, 20, 30, 30, 30]
Pretty sure, that, first of all, I need to clone the largest array and go through its every element and compare it with integers from the smallest array and if values don't match replace it with the closest left (or if there is no such, the right) integer from the smallest array.