Apropos of nothing, here's a code puzzle.
Rules:
- You have an array of strings, eg: ['a', 'at', 'cat', 'scat', 'catch'].
- Return the first value that matches a regex pattern, eg: '.+at' would match cat, scat, catch; but we want cat returned.
- Do not use any looping statements (eg: do/for/while etc).
- Bear in mind functions are not statements ;-)
- The array could be very long, the strings could be very long, and the pattern could be complex. But the desired value could be early in the array.
- Use any language.
The prize:
Nothing really. Well: nothing at all.
Put yer answer in a Gist (or similar) and the URL to the Gist in a comment. IE: do not post code in a comment.
Righto.
--
Adam