Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed onboarding #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

completed onboarding #36

wants to merge 2 commits into from

Conversation

lmieu
Copy link

@lmieu lmieu commented Jan 19, 2017

array_of_words.each do |word|
key = word.upcase.capitalize #downcase to prevent case mattering
if list.has_key? key #if word already exists, inc count
list["#{key}"]=list["#{key}"]+1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since key is a string, there's no need to interpolate it into a new string. "#{key}" is better written as key.

When you want to increment a value in Ruby, the typical syntax is: foo += 1.

Together: list[key] += 1

#reads file in and returns array for printing
def generate_list filename
input = File.new filename, "r+" #opens file for reading
list = Hash.new #creates hash for wordcount list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can instantiate Hashes with a default value that is used when a key is not found. Use Hash.new(0) here and you won't need to check if a given key is already in the hash when you need to increment its value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants