def merge(a1, a2):
    """
    Merges two arrays of numbers (both of which are expected to be pre-sorted into ascending order),
    into a new array, sorted in ascending order.
    """

    nTotalLength = len(a1) + len(a2)
    aMerged = []
    i = 0
    j = 0

    while len(aMerged) < nTotalLength:
        if i == len(a1):
            aMerged.append(a2[j])
            j = j + 1
        elif j == len(a2):
            aMerged.append(a1[i])
            i = i + 1
        elif a1[i] <= a2[j]:
            aMerged.append(a1[i])
            i = i + 1
        else:
            aMerged.append(a2[j])
            j = j + 1

    return aMerged