Creating a functional version of array filtering