Can someone explain me this:


#1

what does this code actually do??

frequencies[word] += 1


Https://discuss.codecademy.com/c/ruby/create-a-histogram/
#2

It adds 1 to the key value for word.

Recall that we declared frequencies as a hash and set the default value of any new key to zero.

frequencies = Hash.new(0)

At this point the hash is empty so has no keys. When we insert a new key (one that does not already exist) it first gets inserted, then its default value is set, and then we increment it.

frequencies[word] += 1

Now any subsequent encounters of that same word will accumulate on that key value.

Note

Recall that dictionaries are arbitrary collections, and like a set have no duplicate keys.


#3

sir i am not getting into this…
for eg. this input text is : "the cow is in the table "
how this code works in this input. can u please explain sir


#4

Please post a link to the exercise. Thanks.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.