If you just need to concatenate all Arrays, you could write a simple helper function, that makes use of Array.prototype.reduce
and Array.prototype.concat
function concatAll () {
return [].reduce.call (arguments, function (a,b) {return a.concat (b)},[])
}
To use it, simply call it with all arrays you want to concatenate.
var a = ["a1", "a2", "a3"],
b = ["b1", "b2", "b3"],
c = ["c1", "c2", "c3"];
concatAll (a,b,c) //["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"]
If you need to sort you array after that too, Array.prototype.sort
takes a function as parameter which you can use to sort after your numerical value first, by putting a weight on it.
concatAll (a,b,c).sort(function (a, b) {
var aVals = a.match(/(\D*)(\d*)/),
bVals = b.match(/(\D*)(\d*)/),
weighted = [a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0, b[1] - a[1]] //[string,number]
return weighted[0] - 2 * weighted[1] // give the number a double weight
}) //["a1", "b1", "c1", "a2", "b2", "c2", "a3", "b3", "c3"]
Heres an example on jsFiddle