These two functions "compareAny" and "compareAll" are a pure example of code being far from being optimized. Those 2 functions are look identical as almost product of copy-paste. You need to think of the way to optimize it and create one function instead of 2.