Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4558

Counting how many times the same elements occurs in an array?

Path csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.stack.nl!talisker.lacave.net!lacave.net!not-for-mail
From Thomas Greenwood <nedpointsman@gmail.com>
Newsgroups comp.lang.ruby
Subject Counting how many times the same elements occurs in an array?
Date Sun, 15 May 2011 05:01:09 -0500
Organization Service de news de lacave.net
Lines 21
Message-ID <6a81112b3af069fa30e1c843c72f8be9@ruby-forum.com> (permalink)
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1305454300 24451 65.111.164.187 (15 May 2011 10:11:40 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Sun, 15 May 2011 10:11:40 +0000 (UTC)
X-Received-From This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway
X-Mail-Count 383270
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <6a81112b3af069fa30e1c843c72f8be9@ruby-forum.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:4558

Show key headers only | View raw


There's probably a fairly simple way to do this.

Basically I'm reading data from an xml file, I need to figure out how
many times identical data occurs in certain attributes, so far I've got
the data into two identical arrays and had the intention of nesting
iterators - seeing if the element was equal to the second and
incrementing every time a match was found. That obviously didn't work
out the way I initially thought.

This seems to be the jist of what I want but it's obviously returning a
count on every iteraton whereas I only want the final tally.

xml_events.each{|x|
  puts "#{x} occurs #{xml_events.count(x)} times"
}

Any ideas?

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Counting how many times the same elements occurs in an array? Thomas Greenwood <nedpointsman@gmail.com> - 2011-05-15 05:01 -0500
  Re: Counting how many times the same elements occurs in an array? John Feminella <johnf@bitsbuilder.com> - 2011-05-15 06:49 -0500
  Re: Counting how many times the same elements occurs in an array? Robert Klemme <shortcutter@googlemail.com> - 2011-05-15 13:52 +0200
  Re: Counting how many times the same elements occurs in an array? Thomas Greenwood <nedpointsman@gmail.com> - 2011-05-15 08:06 -0500
    Re: Counting how many times the same elements occurs in an array? Robert Klemme <shortcutter@googlemail.com> - 2011-05-15 15:37 +0200
    Re: Counting how many times the same elements occurs in an array? 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-15 15:01 -0500
      Re: Counting how many times the same elements occurs in an array? Adam Prescott <adam@aprescott.com> - 2011-05-15 15:21 -0500
      Re: Counting how many times the same elements occurs in an array? David Jacobs <developer@wit.io> - 2011-05-15 15:33 -0500

csiph-web