Friday, July 10, 2009

Hint #2 for the mode homework assignment

Hi All,

This is a bit of a spoiler is you are trying to do the homework on your own. But if you need a little help, please read on:

To create a hash of an array, you can create an empty array, then add each value of the array to the hash as a key and set the value of each key to be equal to 0.

Like this:

h = Hash.new
a = [1, 2, 2, 3, 3, 1]
a.each { |e| h[e] = 0 }

Hint #3 to follow tomorrow morning.

Enjoy your weekend!

Glenn

No comments:

Post a Comment