Given the input array:
array = [ 1, 2, 4, 591, 392, 391, 2, 5, 10, 2, 1, 1, 1, 20, 20 ]
The expected output is:
[ [ 1, 1, 1, 1 ], [ 2, 2, 2 ], 4, 5, 10, [ 20, 20 ], 391, 392, 591 ]
Using the following function to generate the result:
var array = [ 1, 2, 4, 591, 392, 391, 2, 5, 10, 2, 1, 1, 1, 20, 20]
function answer(ArrayFromAbove) {
var length = array.length;
for (var i = 0; i < length; i++) {
for (var j = 0; j < (length - i - 1); j++) {
if (array[j] > array[j + 1]) {
var tmp = array[j];
array[j] = array[j + 1];
array[j + 1] = tmp;
}
}
}
}
answer(array);
console.log(array);
Expected return value:
[ [ 1, 1, 1, 1 ], [ 2, 2, 2 ], 4, 5, 10, [ 20, 20 ], 391, 392, 591 ]