# 034: Filter
# Keep only elements that match a condition

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Keep even numbers
evens = numbers.filter((x) => x % 2 == 0)
show evens  # [2, 4, 6, 8, 10]

# Keep numbers greater than 5
large = numbers.filter((x) => x > 5)
show large  # [6, 7, 8, 9, 10]

# Filter objects
users = [
  { name: "Alex", age: 28, active: true },
  { name: "Jordan", age: 17, active: true },
  { name: "Casey", age: 30, active: false }
]

# Keep active adults
active_adults = users.filter((user) => user.age >= 18 and user.active)
show active_adults  # [{ name: "Alex", age: 28, active: true }]

# Filter strings
words = ["hello", "hi", "goodbye", "bye"]
short_words = words.filter((word) => word.length <= 3)
show short_words  # ["hi", "bye"]
