I am trying to figure out how to have 2 arrays balanced by their weight.
I already have an array that stores 10 integers. Like this example:
var arrayToSplit = new Array();
arrayToSplit = [1, 1, 4, 2, 3, 2, 3, 1, 4, 2];
I need to take these values and push them onto 2 new arrays, but with one condition:
I need to have the same weight or similar between them and both arrays with 5 numbers . So it looks like this.
new array = [4, 3, 2, 1, 1];
new array2 = [4, 3, 2, 1, 2];
source
share