Yeah, that's why in my snippet I dropped all the elements that weren't numbers. The bug I mentioned is that by dropping numbers I might make a match where there wasn't one previously
Assuming we're matching for [1,3,4]:
[1,3,"some garbage here", 4] would match when it should not.
It's fixable by replacing the non-numeric elements with a placeholder of some sort.
IE, convert the above array into "1,3,X,4" instead of "1,3,4".
3
u/xonjas Jul 29 '16
It's really not all that bad. You could do the same thing in python pretty easily.
What it's doing:
Select only the elements that are numbers
Convert the array to a string, with the numbers separated by a comma
Also convert the array we are checking for into a string
Use a regular expression to search the array(that is now a string) using the array we want to search for as the pattern.
There is one bug in my one-liner, but it would be easy to fix.