function merge(left, right){
    var result = [];

    while (left.length > 0 && right.length > 0){
        if (left[0] < right[0]){
            result.push(left.shift());
        } else {
            result.push(right.shift());
        }
    }

    result = result.concat(left).concat(right);
    
    //make sure remaining arrays are empty
    left.splice(0, left.length);
    right.splice(0, right.length);
    
    return result;
}
Merges to arrays in order based on their natural
relationship.
@param {Array} left The first array to merge.
@param {Array} right The second array to merge.
@return {Array} The merged array.