Attenuate is the filtering function. It doesn't make much sense to me to write another function that would aid this one. I'd still have to know how they want to filter the results so I don't understand how the GT/LT/EQ is debilitating. I can explain algorithmically what the function is doing.
- If 0 arguments are passed return an error
- If 1 argument is passed return the array or return error
- If more than one argument is passed assume the first argument is an array, if not return error
- If remaining arguments were passed as an array pop them from the passed arguments array
- Take the first argument of the remaining args and assume it is the key to filter by
- Take the second argument of the remaining args and assume it is the operation to be performed
- If the operation is LT|GT|EQ|LTEQ|GTEQ then only take one argument as the filter value
- If the the operation is LTGT|GTLT|LTEQGT|GTEQLT|LTGTEQ|GTLTEQ|LTEQGTEQ|GTEQLTEQ then take the next two arguments as the filtering value
- Repeat until there are no more arguments left
- Look at each value of the array, if it's an array then recurse the function
- If the returned result is different from the value then unset that portion of the array
- If the value is not an array then proceed to filter results only if the key passed through parameters is the same as the current key of the data
- If an i was present in the filtering operation then assume we want case insensitivity of strings
- Check the actual value to determine if it is a string or not
- Irrelevant of the type of checking denote that a value greater results in 1 a value less than results in -1 and equality results in 0
- Based on the previous results and the operation type determine the range of values which satisfy the filtering operation and unset any that do not
- Return the filtered array