# Method to create a list
# input: string of items separated by spaces (example: "carrots apples cereal pizza")
# steps:
  # create a hash for our grocery
  # key == item and value == quantity
  # set default quantity
  # print the list to the console [can you use one of your other methods here?]
# output: hash

# Method to add an item to a list
# input: item name and optional quantity
# steps: define the method with two parameters (item, quantity)
# push that into a hash
# output:

# Method to remove an item from the list
# input: two parameters (item, quantity)
# steps: define the method
# find the key/value for the item we want to remove
# remove the item from the hash
# output: return an updated (could be sent to the print method)

# Method to update the quantity of an item
# input: two parameters (item, quantity)
# steps: add/update the item/quantity in the hash
# output: return an updated

# Method to print a list and make it look pretty
# input: the most recent (updated) verstion of the hash
# steps: iterate over the hash
# output: print out each key/value pair

string = "carrots apples cereal pizza"

def create_list(string)
  grocery_list = {}
  string.split.each do |item|
    grocery_list[item] = 1
  end
  p grocery_list
end

def add_item(grocery_list, item, quantity)
  grocery_list[item] = quantity
end

def remove_item(grocery_list, item)
  grocery_list.delete(item)
end

def update_item(grocery_list, item, quantity)
  grocery_list.update({item => quantity})
end

def print_list(grocery_list)
  grocery_list.each do |item, quantity|
    puts "#{item}, qty = #{quantity}"
  end
end

new_hash = create_list("carrots apples cereal pizza")
add_item(new_hash,'tomatoes', 3)
remove_item(new_hash,'carrots')
update_item(new_hash,'tomatoes', 2)
p new_hash
print_list(new_hash)


=begin

What did you learn about pseudocode from working on this challenge?

I learned that it is very imporatant (and I think I even said this at one point) that you should write down each and every step no matter how insignificant you think it is.  This can help you if you hit any snags when writing your code.  Sometimes it is the smallest details that can help correct (or sometimes mess up) your work.

What are the tradeoffs of using Arrays and Hashes for this challenge?

My pair and I both immediately agreed that using a hash for the list was best.  Our reasoning is that arrays are pre-indexed and we preferred the flexibility of being able to use the keys in a hash for our item names and the values as the quantities of the corresponding item.

What does a method return?

A method will return the result of the last evaluation in the method.  This is called an implicit return.

What kind of things can you pass into methods as arguments?

Pretty much anything:  strings, floats/integers, arrays, hashes, other methods to name a few.

How can you pass information between methods?

By defining a method as a variable and then passing those variables into another method, as we did with our create_list method (by assigning it to the variable new_hash, which was then passed to each or our successive methods.)

What concepts were solidified in this challenge, and what concepts are still
confusing?

I feel like iteration was further solidified for me as was method definition.  I am still a little fuzzy about passing information between methods (without using classes) but my eyes were definitely opened wider by this GPS.

=end