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

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

Към профила на Ангел Новоселски

Резултати

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

Код

def convert_to_bgn(price, currency)
case currency
when :usd
(price * 1.7408).round(2)
when :eur
(price * 1.9557).round(2)
when :gbp
(price * 2.6415).round(2)
else
price.round(2)
end
end
def compare_prices(first_price, first_currency, second_price, second_currency)
first_bgn = convert_to_bgn(first_price, first_currency)
second_bgn = convert_to_bgn(second_price, second_currency)
first_bgn <=> second_bgn
end

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

........

Finished in 0.00631 seconds
8 examples, 0 failures

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

Ангел обнови решението на 12.10.2015 13:38 (преди над 8 години)

+def convert_to_bgn(price, currency)
+ if currency == :usd
+ (price * 1.7408).round(2)
+ elsif currency == :eur
+ (price * 1.9557).round(2)
+ elsif currency == :gbp
+ (price * 2.6415).round(2)
+ else
+ price.round(2)
+ end
+end
+
+def compare_prices(first_price, first_currency, second_price, second_currency)
+ first_bgn = convert_to_bgn(first_price, first_currency)
+ second_bgn = convert_to_bgn(second_price, second_currency)
+ first_bgn <=> second_bgn
+end

Ангел обнови решението на 12.10.2015 14:44 (преди над 8 години)

def convert_to_bgn(price, currency)
- if currency == :usd
+ case currency
+ when :usd
(price * 1.7408).round(2)
- elsif currency == :eur
+ when :eur
(price * 1.9557).round(2)
- elsif currency == :gbp
+ when :gbp
(price * 2.6415).round(2)
else
price.round(2)
end
end
def compare_prices(first_price, first_currency, second_price, second_currency)
first_bgn = convert_to_bgn(first_price, first_currency)
second_bgn = convert_to_bgn(second_price, second_currency)
first_bgn <=> second_bgn
end