def merge(intervals):
    """ Turns `intervals` [[0,2],[1,5],[7,8]] to [[0,5],[7,8]].
    """
    out = []
    for i in sorted(intervals, key=lambda i: i[0]):
        if out and i[0] <= out[-1][1]:
            out[-1][1] = max(out[-1][1], i[1])
        else:
            out += i,
    return out