Merge to number

Here’s an idea to handle different length arrays the way you describe your output:

function max_pair(a, b)
    na, nb = length(a), length(b)
    na == nb && return max.(a, b)

    # make sure a is the longer one
    if nb > na
        a, b = b, a
        na, nb = nb, na
    end
    # compare the comparable
    maxes = max.(a[1:nb], b)
    # append the rest
    append!(maxes, a[nb+1:end])
    return maxes
end
1 Like