how to count values in an array using 1.8.6 ?

R

Richard Sandoval

Hi,

How can I count all keys in an array?

For instance, I want to do this
countme = [1,2,3,4,4,4,4,4,5] => [1, 2, 3, 4, 4, 4, 4, 4, 5]
countme.count
=> 9

but in ruby 1.8.6, there is only size which doesn't quite work...
 
R

Roy Zuo

How about

countme.uniq.size

Hi,

How can I count all keys in an array?

For instance, I want to do this
countme = [1,2,3,4,4,4,4,4,5] => [1, 2, 3, 4, 4, 4, 4, 4, 5]
countme.count
=> 9

but in ruby 1.8.6, there is only size which doesn't quite work...

--
______________________________________________________
/ yo-yo, n.: \
| |
| Something that is occasionally up but normally down. |
| |
\ (see also Computer). /
 
D

Dominik Honnef

Richard Sandoval said:
Hi,

How can I count all keys in an array?

For instance, I want to do this
countme = [1,2,3,4,4,4,4,4,5] => [1, 2, 3, 4, 4, 4, 4, 4, 5]
countme.count
=> 9

but in ruby 1.8.6, there is only size which doesn't quite work...


I can't quite see what the problem is here.

In 1.9.x, Array#{length,size,count} are synonymous, and 1.8.6 is just
missing the last of those, #count. #length and #size still behave the
exact same and return 9 for your example array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top