A

Admin • 833K Points
Coach

Q. What is the result of this code?

Code:
let list = [1, 2, 3, 4]
print(list.filter { $0 % 2 == 0 })
  • (A) [1, 3]
  • (B) [2, 4]
  • (C) [1, 2, 3, 4]
  • (D) [0, 2]
  • Correct Answer - Option(B)
  • Views: 25
  • Filed under category Swift (iOs)
  • Hashtags:

Explanation by: Admin

`filter` returns all elements where the condition is true, i.e., even numbers.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.