Codington
0 of 6 problems solved0%

Keep Even Numbers

Arrays of numbers are common, and filtering by a simple predicate is a great starting point. Here you'll use filter with a small helper to keep only even numbers. The result should be a new number[].

This problem reinforces reading from a number[], writing a boolean-returning predicate, and returning a new array without mutating the input.

Your Task

  • Complete the function isEven(n: number): boolean.
  • Complete the function keepEven(nums: number[]): number[] using isEven.
  • Do not mutate the input array.

Examples

keepEven([1, 2, 3, 4, 5])[2, 4] keepEven([])[]