I have two one-dimensional arrays, aand b. amatters and is bempty. Length ais an even number. I would like to remove any other value from aand move them bin the same order in which they were placed in a.
var a = [1, 2, 3, 4, 5, 6], b = [];
becomes
var a = [1, 3, 5], b = [2, 4, 6];
I realized that I would filterdo the trick, but I'm not so happy with its performance, as the average length ais 300-400.
b = a.filter((i, idx) => {
return idx % 2 == 0;
});
a = a.filter((i, idx) => {
return idx % 2 == 1;
});
I also looked at lodash to see if there is anything in this library that could help me, and the only function that is next to what I'm looking for is . _.chunk(array, \[size=1\])
I appreciate any help to help me find the best and fastest way to do this.