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

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

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

Резултати

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

Код

def convert_to_bgn(amount,currency)
case currency
when :bgn
amount.round(2)
when :usd
(amount * 1.7408).round(2)
when :eur
(amount * 1.9557).round(2)
when :gbp
(amount * 2.6415).round(2)
end
end
def compare_prices(first_amount,first_currency,second_amount,second_currency)
convert_to_bgn(first_amount,first_currency) <=>
convert_to_bgn(second_amount,second_currency)
end

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

........

Finished in 0.00633 seconds
8 examples, 0 failures

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

Слави обнови решението на 12.10.2015 07:42 (преди над 8 години)

+def convert_to_bgn(amount,currency)
+ case currency
+ when :bgn
+ amount.round(2)
+ when :usd
+ (amount * 1.7408).round(2)
+ when :eur
+ (amount * 1.9557).round(2)
+ when :gbp
+ (amount * 2.6415).round(2)
+ end
+end
+
+def compare_prices(first_amount,first_currency,second_amount,second_currency)
+ convert_to_bgn(first_amount,first_currency) <=>
+ convert_to_bgn(second_amount,second_currency)
+end