Last active
November 21, 2018 10:49
-
-
Save harrisonmalone/dc59f0779079fdb4b7bf4287399deef7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| items = [{ customer: "John", item: "Soup", cost: 8.50}, {customer: "Sarah", item: "Pasta", cost: 12}, {customer: "John", item: "Coke", cost: 2.50}] | |
| puts "whats your name?" | |
| customer = gets.chomp | |
| filter = items.select do |item| | |
| item[:customer] == customer | |
| end | |
| cost = filter.map do |item| | |
| item[:cost] | |
| end | |
| result = cost.sum | |
| p "#{customer} owes $#{result}" | |
| # this is a really nice challenge for working with select and map | |
| # need to select only the items that contain the name and then just take the cost items out of that array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment