filter([1, 2, 3, 4, 5], x => x % 2 === 0) // β [2, 4]A generic filter<T> accepts a predicate and returns only elements for which it is true.
Challenge: Implement filter<T>(arr: T[], pred: (x: T) => boolean): T[].
filter([1,2,3,4,5], x => x % 2 === 0) // β [2, 4]