fancy trick to avoid two additional while loops - use Array.prototype.concat