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

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

Към профила на София Петрова

Резултати

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

Код

EXCHANGE_RATES = {usd: 1.7408, eur: 1.9557, gbp: 2.6415, bgn: 1.0}
def convert_to_bgn(price, currency)
(EXCHANGE_RATES[currency] * price).round(2)
end
def compare_prices(first_price, first_currency, second_price, second_currency)
first_to_bgn = convert_to_bgn(first_price, first_currency)
second_to_bgn = convert_to_bgn(second_price, second_currency)
first_to_bgn <=> second_to_bgn
end

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

........

Finished in 0.00636 seconds
8 examples, 0 failures

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

София обнови решението на 09.10.2015 01:54 (преди над 8 години)

+CURRENCIES = {usd: 1.7408, eur: 1.9557, gbp: 2.6415, bgn: 1.0}
+
+def convert_to_bgn(price, currency)
+ (CURRENCIES[currency] * price).round(2)
+end
+
+def compare_prices(first_price, first_currency, second_price, second_currency)
+ first_to_bgn = convert_to_bgn(first_price, first_currency)
+ second_to_bgn = convert_to_bgn(second_price, second_currency)
+ first_to_bgn <=> second_to_bgn
+end

София обнови решението на 09.10.2015 21:25 (преди над 8 години)

-CURRENCIES = {usd: 1.7408, eur: 1.9557, gbp: 2.6415, bgn: 1.0}
+EXCHANGE_RATES = {usd: 1.7408, eur: 1.9557, gbp: 2.6415, bgn: 1.0}
def convert_to_bgn(price, currency)
- (CURRENCIES[currency] * price).round(2)
+ (EXCHANGE_RATES[currency] * price).round(2)
end
def compare_prices(first_price, first_currency, second_price, second_currency)
first_to_bgn = convert_to_bgn(first_price, first_currency)
second_to_bgn = convert_to_bgn(second_price, second_currency)
first_to_bgn <=> second_to_bgn
end