Busy learning Ruby… the documentation have an example:
‘hello world’.count(‘lo’, ‘o’) that return 2 how does that return 2?
In my example I’ve: puts ‘Lennie’.count(‘Le’, ‘ie’) that return 2.
How does count work in this regard?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
'hello world'.count('lo')returns five. It has matched the third, fourth, fifth, eighth, and tenth characters. Lets call this set one.'hello world'.count('o')returns two. It has matched the fifth and eighth characters. Lets call this set two.'hello world'.count('lo', 'o')counts the intersection of sets one and two.The intersection is a third set containing all of the elements of set two that are also in set one. In our example, both sets one and two contain the fifth and eighth characters from the string. That’s two characters total. So,
countreturns two.