Make a function that removes elements from the end of an array until the passed function returns true and returns the remaining elements in the array.