Решение на Първа задача от Славяна Монкова

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

Към профила на Славяна Монкова

Резултати

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

Код

def convert_to_bgn(price, currency)
price_bgn = case currency
when :bgn then price
when :usd then price * 1.7408
when :eur then price * 1.9557
when :gbp then price * 2.6415
end
price_bgn.round(2)
end
def compare_prices(first_price, currency_first, second_price, currency_second)
first_bgn_price = convert_to_bgn(first_price, currency_first)
second_bgn_price = convert_to_bgn(second_price, currency_second)
(first_bgn_price - second_bgn_price).round(2)
end

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

........

Finished in 0.00635 seconds
8 examples, 0 failures

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

Славяна обнови решението на 11.10.2015 18:37 (преди над 8 години)

+def convert_to_bgn(price, currency)
+ price_bgn = case currency
+ when :bgn then price
+ when :usd then price * 1.7408
+ when :eur then price * 1.9557
+ when :gbp then price * 2.6415
+ end
+ price_bgn.round(2)
+end
+
+
+def compare_prices(first_price, currency_first, second_price, currency_second)
+ first_bgn_price = convert_to_bgn(first_price, currency_first)
+ second_bgn_price = convert_to_bgn(second_price, currency_second)
+
+ (first_bgn_price - second_bgn_price).round(2)
+end

Като цяло добро решение

  • Оправи индентацията. Подравни първия when в convert_to_bgn. Използвай два space-a в compare_prices
  • Беше ли нужно round(2) в compare_prices?
  • Имената ти като цяло са добри, само може да ги направиш една идея по-консистентни. Защо не first_currency, имайки предвид реда в first_price