code: def intersect_range_array(bed1,beds2,payload=None,is_sorted=False):
    if not is_sorted: beds2 = sort_ranges(beds2)
    output = []
    for bed2 in beds2:
      cval = bed2.cmp(bed1)
      if cval == -1: continue
      elif cval == 0:
        output.append(bed1.intersect(bed2))
        if payload==1:
          output[-1].set_payload(bed1.payload)
        if payload==2:
          output[-1].set_payload(bed2.payload)
      elif cval == 1: break
    if payload: return sort_ranges(output)
    return merge_ranges(output)