# Method to create a list
# input: string of items separated by spaces (example: "carrots apples cereal pizza")
# steps: 
#Step 1: Create a new variable, grocery_list, as a new hash.
#Step 2: Add item as string for keys.
#Step 3: Set values = 1.
#Step 4: Iterate over the hash.

  # set default quantity
# print the list to the console [we can use our laste method.]
# output: Hash

# Method to add an item to a list
# input: hash, keys(items), values(qty = 1)
#steps: add item and quantity to list
#output:  original list or updated list

# Method to remove an item from the list
# input: hash, keys(items), values(qty = 1)
# steps: iterate over string on list
       # delete item and its quantity
# output: updated list

# Method to update the quantity of an item
# input: hash, keys(items), values(qty = 1)
# steps: iterate over values / update list so that new value replaces old value
# output: updated list

# Method to print a list and make it look pretty
# input: hash, keys(items), values(qty = 1)
# steps: print list as a string
# output printed out list

#release 2
#initial solutions


# From psuedoode - "carrots apples cereal pizza" that is example input for this method

#first solution

# def new_list(item_input)
#   grocery_items = item_input.split(' ')
#   list = Hash.new{}
#   grocery_items.each do |grocery_items|
#     list[grocery_items] = 1
#   end
#   return list
# end

#refactored solution

def new_list(item_input)
  list = Hash.new(0)
  item_input.split.each{|items| list[items] += 1}
  return list
end

# groceries = new_list("carrots apples cereal pizza")

# p groceries

def add_item(list, item, quantity=1)
  list[item] = quantity 
  return list
end

# add_item(groceries, "lemonade", 2)

# p groceries 

def remove_item(list, item)
  list.delete(item)
  return list
end

# remove_item(groceries, "carrots")

# p groceries

def update_quantity(list, item, quantity)
  list[item] = quantity
  return list
end

# update_quantity(groceries, "apples", 4)

# p groceries

def print_list(list)
  list.each do |x,y|
      puts x + ": " + y.to_s
  end
end

# print_list(groceries)

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

# I learned that good pseudocode translates to good code.
# I'm not one to pseudocode as well as I should and at first having weak pseudocode did translate to struggling
# but when we solidified our pseudocode it went a lot smoother. 

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

# Arrays have to be in order and don't have values so it was essential for us to use hashes for the grocery list that had values as well as keys

# What does a method return?

# A method returns the result of running the code it contains.

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

# Arguments can include almost any object included but not limited to Strings, Fixnums, Arrays, Hashes, symbols, and blocks.

# How can you pass information between methods?

# Information can be passed between methods by storing that method in a variable and using that variable as the input of another method. Another option would be to use instance variables.


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

# pseudocode was solidified and printing lists as well as testing methods to make sure they work.
