Решение на Първа задача от Мирослав Лалев

Обратно към всички решения

Към профила на Мирослав Лалев

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)

Код

def convert_to_bgn(amount, currency)
conversion_rate = {:usd => 1.7408, :eur => 1.9557, :bgn => 1, :gbp => 2.6415}
(amount*conversion_rate[currency]).round(2)
end
def compare_prices(amount_one, currency_one, amount_two, currency_two)
first_amount_to_bgn = convert_to_bgn(amount_one, currency_one)
second_amount_to_bgn = convert_to_bgn(amount_two, currency_two)
first_amount_to_bgn <=> second_amount_to_bgn
end

Лог от изпълнението

........

Finished in 0.00637 seconds
8 examples, 0 failures

История (2 версии и 1 коментар)

Мирослав обнови решението на 08.10.2015 21:07 (преди около 9 години)

+def convert_to_bgn(price, value_type)
+ values_hash = Hash[:usd => 1.7408, :eur => 1.9557, :bgn => 1, :gbp => 2.6415]
+ (price*values_hash[value_type]).round(2)
+end
+
+def compare_prices(first, first_type, second, second_type)
+ convert_to_bgn(first, first_type) <=> convert_to_bgn(second, second_type)
+end

Мирослав обнови решението на 10.10.2015 18:00 (преди около 9 години)

-def convert_to_bgn(price, value_type)
- values_hash = Hash[:usd => 1.7408, :eur => 1.9557, :bgn => 1, :gbp => 2.6415]
- (price*values_hash[value_type]).round(2)
+def convert_to_bgn(amount, currency)
+ conversion_rate = {:usd => 1.7408, :eur => 1.9557, :bgn => 1, :gbp => 2.6415}
+ (amount*conversion_rate[currency]).round(2)
end
-def compare_prices(first, first_type, second, second_type)
- convert_to_bgn(first, first_type) <=> convert_to_bgn(second, second_type)
+def compare_prices(amount_one, currency_one, amount_two, currency_two)
+ first_amount_to_bgn = convert_to_bgn(amount_one, currency_one)
+ second_amount_to_bgn = convert_to_bgn(amount_two, currency_two)
+ first_amount_to_bgn <=> second_amount_to_bgn
end