I am looking for an efficient way of evaluating an array of strings against a series of rules and then adding them to another array.
For example I have an array of strings:
- something
- a
- 1234
- #gohere
I want to iterate through all the items in the array and evaluate them based on a series of rules. For example:
- Strings greater that 1 in length
- Strings that don't start with the # character
I was thinking of either:
- Nested loop of if statements evaluating the string for each rule and if they all pass then add to another array
- Evaluating the string against rule 1 then adding to the array then performing another evaluation - I have discounted this since it requires lots of array read/write operations to evaluate the complete ruleset.
Please note that I have kept the number of rules to two for brevity however I could be needing up to 10 rules. Additionally, I do not control the original array since the function I am calling returns an array of strings.
I know I may have answered my own question with the nested loop however I wondered if anyone had any ideas for optimizing this type of situation.
Also, I know I asked this question in the reference of Ruby but any pseudo-code would suffice.