This comment is hidden because it contains spoiler information about the solution
this code is awesome in optimization wise.
I don't understand how this handles double spaces. Could someone explain, please?
Me, too. But hey! Now we know!
If the requirements state "10 or more," then I think it is better to translate that language directly to code (i.e., "foo >= 10") rather than to a logical but inferred equivalent.
However obvious the inference might seem to you, it might not be so obvious to the maintenance developer who needs to understand how your code manages to fulfill (or, if he is fixing a defect, how it fails to fulfill) the requirements.
An obvious exception is when performance is an issue--but, then, only when performance is an active, demonstrable issue. (In this case, there is no performance advantage either way.)
I have quite simlar solutions. And I found that -5/2 != -(5/2) in Ruby. It's very intersting. Becuase (-2.5).to_i == -2. So it's a wise decision to use i variable.
-5/2 != -(5/2)
(-2.5).to_i == -2
Pros: returns the correct data (count) that we need, so less overhead (?)
Cons: does not accept array inputs
Pros: accepts array inputs & is designed to find matchind elements in an array
Cons: returns matched elements, which we then have to count
Personally, I think preg_match_all is clever, but in the field, preg_grep is clearer about what it does, reducing confusion. If performance is an issue and preg_match_all is shown to be faster, then it could be used. Just know it's limitations (as mentioned in the comments), know your inputs, and write some good test cases.
Yeah, I'd like to know as well
nifty solution. Had it going in the back of the head. But then ADD kicked in :( and i veered off in the domain of that awful vicious circle called "conditionals".
Also, there are extra parentheses around the explode.
There is a difference between signed zero and a "regular" zero. A signed zero can represent an underflow and discontinuous function. In scientific computing, a signed zero is used when rounding off extremely small negative numbers.
>>> 1 or 0
>>> 0 or 1
>>> [1, 2] or 
>>> None or 
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'NoneType' has no len()
Straight up gangsta!