input: Write a function to rearrange an array by alternating even and odd numbers.
  assert rearrange([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[2, 1, 4, 3, 6, 5, 8, 7]
  assert rearrange([10, 21, 32, 43, 54, 65])==[10, 21, 32, 43, 54, 65]
  assert rearrange([5, 8, 6, 3, 2, 7])==[8, 5, 6, 3, 2, 7]
output: def rearrange(arr):
      evens = [x for x in arr if x % 2 == 0]
      odds = [x for x in arr if x % 2 != 0]
      result = []
      
      i, j = 0, 0
      while i < len(evens) and j < len(odds):
          result.append(evens[i])
          result.append(odds[j])
          i += 1
          j += 1
      
      while i < len(evens):
          result.append(evens[i])
          i += 1
      
      while j < len(odds):
          result.append(odds[j])
          j += 1
      
      return result