Last active
August 29, 2015 13:56
-
-
Save gstark/9259655 to your computer and use it in GitHub Desktop.
This file contains 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
# 004 | |
sorted_rates = rates.select { |rate| rate.from != 'USD' }. | |
sort { |a, b| a.from <=> from_cur }. | |
map { |rate| [rate] } | |
# Split the select into two? less efficient but "single responsibility" ? | |
all_paths(sorted_rates).select { |rates_arr| rates_arr.first.from == from_cur && rates_arr.last.to == 'USD' }. | |
sort { |a, b| a.length <=> b.length }. | |
first | |
all_paths(sorted_rates).select { |rates_arr| rates_arr.last.to == 'USD' }. | |
select { |rates_arr| rates_arr.first.from == from_cur }. | |
sort { |a, b| a.length <=> b.length }. | |
first | |
# Does this actually change what is in "paths" | |
left_arr << right_arr.first | |
# 007 | |
def find_common_currency(from, to, table) | |
table[from].keys.each do |k| | |
return k if table[k].has_key?(to) | |
end | |
return nil | |
end | |
def find_common_currency(from, to, table) | |
table[from].keys.find { |k| table[k].has_key?(to) } | |
end | |
# 005 | |
# Unusual to have require_relative INSIDE a class definition | |
require_relative 'international_trade/sales_transactions' | |
require_relative 'international_trade/currency_conversion_table' | |
# Can use select instead of reject and a != (double negatives) | |
sku_items = transactions.reject {|t| t if t.sku != sku } | |
# Do you really mean InternationalTrade to be a Module? -- it has no behavior or state of its own | |
class InternationalTrade | |
class CurrencyConversionTable | |
# This seems like it shouldn't be burried inside CurrencyConversionTable class but at the module level | |
# unless it is only an internal implementation detail | |
class ConversionItem | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment