Решение на Първа задача от Йоан Динков

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

Към профила на Йоан Динков

Резултати

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

Код

def convert_to_bgn(price, currency)
currencies = { usd: 1.7408, eur: 1.9557, gbp: 2.6415, bgn: 1 }
(price * currencies[currency]).round(2)
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.02594 seconds
8 examples, 0 failures

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

Йоан обнови решението на 07.10.2015 21:50 (преди над 8 години)

+def convert_to_bgn(price, currency)
+ currencies = { usd: 1.7408, eur: 1.9557, gbp: 2.6415 }
+
+ (price * currencies[currency]).round(2)
+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

Йоан обнови решението на 08.10.2015 17:45 (преди над 8 години)

def convert_to_bgn(price, currency)
- currencies = { usd: 1.7408, eur: 1.9557, gbp: 2.6415 }
+ currencies = { usd: 1.7408, eur: 1.9557, gbp: 2.6415, bgn: 1 }
(price * currencies[currency]).round(2)
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