Решение на Първа задача от Александър Дражев

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

Към профила на Александър Дражев

Резултати

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

Код

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

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

........

Finished in 0.00713 seconds
8 examples, 0 failures

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

Александър обнови решението на 08.10.2015 08:42 (преди около 9 години)

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

Александър обнови решението на 08.10.2015 20:57 (преди около 9 години)

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