Редни числителни имена

Краен срок
27.10.2016 17:00

Срокът за предаване на решения е отминал

Дефинирайте функцията ordinalize, която приема единствен аргумент number (цяло число) и връща низ, съдържащ съответното на number редно числително име.

Примери:

ordinalize(5)   # => '5th'
ordinalize(12)  # => '12th'
ordinalize(-11) # => '-11th'

Правила за образуване на редни числителни имена в английския език:

  • Към бройното числително се добавя th. Примери: 0 -> 0th, 4 -> 4th, 11 -> 11th, 5111 -> 5111th и т.н.
  • Изключения от правилото:
    • 1 -> 1st, 2 -> 2nd и 3 -> 3rd.
    • 21 -> 21st, 22 -> 22nd и 23 -> 23rd.
    • 31 -> 31st, 32 -> 32nd и 33 -> 33rd.
    • И т.н.

Бележки

  • Върнатият низ е на английски език.
  • Числителните редни в английския език
  • Редното числително се образува като се добави наставка към бройното числително. Очакваме 1st, а не first.
  • Функцията трябва да работи и с отрицателни числа.
  • Функцията приема цяло число, а не низ.

Решения

Христо Владев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Владев
def ordinalize(number)
absolute_value = number.abs
suffix =
if (11..13).cover?(absolute_value % 100)
'th'
else
case absolute_value % 10
when 1 then 'st'
when 2 then 'nd'
when 3 then 'rd'
else 'th'
end
end
"#{number}#{suffix}"
end
.....

Finished in 0.00335 seconds
5 examples, 0 failures
Калина Бухлева
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Калина Бухлева
def ordinalize(number)
if (11..13).include?(number % 100)
"#{number}th"
else
case number % 10
when 1 then "#{number}st"
when 2 then "#{number}nd"
when 3 then "#{number}rd"
else "#{number}th"
end
end
end
...FF

Failures:

  1) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1st"
            got: "-1th"
       
       (compared using ==)
     # /tmp/d20161027-13689-1n1ply2/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-1n1ply2/spec.rb:3:in `each'
     # /tmp/d20161027-13689-1n1ply2/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-1n1ply2/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with big numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1000000001st"
            got: "-1000000001th"
       
       (compared using ==)
     # /tmp/d20161027-13689-1n1ply2/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-1n1ply2/spec.rb:3:in `each'
     # /tmp/d20161027-13689-1n1ply2/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-1n1ply2/spec.rb:87:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00325 seconds
5 examples, 2 failures

Failed examples:

rspec /tmp/d20161027-13689-1n1ply2/spec.rb:53 # #ordinalize works with negative numbers
rspec /tmp/d20161027-13689-1n1ply2/spec.rb:86 # #ordinalize works with big numbers
Здравко Петров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Здравко Петров
def do_magic(n)
ending = case n % 100
when 11, 12, 13 then 'th'
else
case n % 10
when 1 then 'st'
when 2 then 'nd'
when 3 then 'rd'
else 'th'
end
end
ending
end
def ordinalize(n)
ending = do_magic(n.abs)
"#{n}#{ending}"
end
.....

Finished in 0.00378 seconds
5 examples, 0 failures
Петър Нетовски
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Нетовски
ORDINAL_SUFFIXES = {
1 => 'st',
2 => 'nd',
3 => 'rd'
}.freeze
DEFAULT_SUFFIX = 'th'.freeze
EXCEPTIONS_LIST = [11, 12, 13].freeze
def ordinalize(number)
return nil unless number.is_a? Integer
absolute_number = number.abs
number_in_text = number.to_s
if EXCEPTIONS_LIST.include? absolute_number % 100
number_in_text + DEFAULT_SUFFIX
else
number_in_text + ORDINAL_SUFFIXES.fetch(absolute_number % 10, DEFAULT_SUFFIX)
end
end
.....

Finished in 0.00374 seconds
5 examples, 0 failures
Христо Христов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Христов
def ordinalize(number)
legit_hash_name = { '1' => 'st', '2' => 'nd', '3' => 'rd'}
legit_hash_name.default = 'th'
if (number.abs % 100).between?(11, 13) then return number.to_s + "th" end
number.to_s + legit_hash_name[(number.abs%10).to_s]
end
.....

Finished in 0.00397 seconds
5 examples, 0 failures
Мариян Асенов
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Мариян Асенов
def ordinalize(number)
digit = number.abs % 10
exceptions = ['st', 'nd', 'rd']
include_exception = (1..3).include? digit
not_this = !(11..13).include?(number.abs % 100)
number.to_s << exceptions[digit - 1] if include_exception && not_this
number.to_s << 'th'
end
..FFF

Failures:

  1) #ordinalize handles 'first, second, third' special cases
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "1st"
            got: "1th"
       
       (compared using ==)
     # /tmp/d20161027-13689-1foc3g3/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-1foc3g3/spec.rb:3:in `each'
     # /tmp/d20161027-13689-1foc3g3/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-1foc3g3/spec.rb:36:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1st"
            got: "-1th"
       
       (compared using ==)
     # /tmp/d20161027-13689-1foc3g3/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-1foc3g3/spec.rb:3:in `each'
     # /tmp/d20161027-13689-1foc3g3/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-1foc3g3/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  3) #ordinalize works with big numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1000000001st"
            got: "-1000000001th"
       
       (compared using ==)
     # /tmp/d20161027-13689-1foc3g3/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-1foc3g3/spec.rb:3:in `each'
     # /tmp/d20161027-13689-1foc3g3/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-1foc3g3/spec.rb:87:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00323 seconds
5 examples, 3 failures

Failed examples:

rspec /tmp/d20161027-13689-1foc3g3/spec.rb:35 # #ordinalize handles 'first, second, third' special cases
rspec /tmp/d20161027-13689-1foc3g3/spec.rb:53 # #ordinalize works with negative numbers
rspec /tmp/d20161027-13689-1foc3g3/spec.rb:86 # #ordinalize works with big numbers
Ралица Дарджонова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Ралица Дарджонова
def ordinalize(number)
number_to_string = number.to_s
if number.abs / 10 % 10 == 1
number_to_string + 'th'
else
case number.abs % 10
when 1
number_to_string + 'st'
when 2
number_to_string + 'nd'
when 3
number_to_string + 'rd'
else
number_to_string + 'th'
end
end
end
.....

Finished in 0.00357 seconds
5 examples, 0 failures
Светослав Годжев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Светослав Годжев
def ordinalize(number)
result = number.to_s
if result[-2] == '1'
result + 'th'
else
case result[-1]
when '1' then result + 'st'
when '2' then result + 'nd'
when '3' then result + 'rd'
else result + 'th'
end
end
end
.....

Finished in 0.00417 seconds
5 examples, 0 failures
Добрин Цветков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Добрин Цветков
SUFFIXES = { '1' => 'st', '2' => 'nd', '3' => 'rd' }
def ordinalize(number)
number.to_s << case number.abs % 10
when 1..3
if (number.abs / 10) % 10 == 1
'th'
else
SUFFIXES[(number.abs % 10).to_s]
end
else
'th'
end
end
.....

Finished in 0.00334 seconds
5 examples, 0 failures
Христина Тодорова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христина Тодорова
def suffix(number)
case number
when '1' then 'st'
when '2' then 'nd'
when '3' then 'rd'
else 'th'
end
end
def ordinalize(number)
if number <= 9 && number >= -9
number.to_s + suffix(number.to_s.chars[-1])
elsif number.to_s.chars[-2] == '1'
"#{number}th"
else
number.to_s + suffix(number.to_s.chars[-1])
end
end
.....

Finished in 0.0037 seconds
5 examples, 0 failures
Лазар Дилов
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Лазар Дилов
def ordinalize(num)
last_digit = num.to_s.chars.last.to_i
suffix = "th"
return num.to_s + suffix if num.abs == 11 || num.abs == 12 || num.abs == 13
case last_digit
when 2
suffix = "nd"
when 3
suffix = "rd"
when 1
suffix = "st"
end
num.to_s + suffix
end
F..F.

Failures:

  1) #ordinalize adds 'th' to the cardinal number in the common case
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "111th"
            got: "111st"
       
       (compared using ==)
     # /tmp/d20161027-13689-9b6f4e/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-9b6f4e/spec.rb:3:in `each'
     # /tmp/d20161027-13689-9b6f4e/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-9b6f4e/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-111th"
            got: "-111st"
       
       (compared using ==)
     # /tmp/d20161027-13689-9b6f4e/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-9b6f4e/spec.rb:3:in `each'
     # /tmp/d20161027-13689-9b6f4e/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-9b6f4e/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00363 seconds
5 examples, 2 failures

Failed examples:

rspec /tmp/d20161027-13689-9b6f4e/spec.rb:8 # #ordinalize adds 'th' to the cardinal number in the common case
rspec /tmp/d20161027-13689-9b6f4e/spec.rb:53 # #ordinalize works with negative numbers
Петко Митков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Петко Митков
def ordinalize(number)
str_num = number.to_s
case str_num
when /[0,2-9]1$/ , /^(-)?1$/
str_num + 'st'
when /[0,2-9]2$/, /^(-)?2$/
str_num + 'nd'
when /[0,2-9]3$/, /^(-)?3$/
str_num + 'rd'
else
str_num + 'th'
end
end
.....

Finished in 0.00371 seconds
5 examples, 0 failures
Божидар Михайлов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Михайлов
def ordinalize(n)
ps = [['1.', 'th'], ['1', 'st'], ['2', 'nd'], ['3', 'rd'], ['', 'th']]
n.to_s + ps.each { |regx, repl| break repl if n.to_s =~ /.*#{regx}$/ }
end
.....

Finished in 0.00723 seconds
5 examples, 0 failures
Мила Бянкова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Мила Бянкова
def ordinalize(number)
suffix = 'th'
case last_digit(number)
when 1
suffix = 'st' unless second_last_digit(number) == 1
when 2
suffix = 'nd' unless second_last_digit(number) == 1
when 3
suffix = 'rd' unless second_last_digit(number) == 1
end
number.to_s + suffix
end
def last_digit(number)
number.abs % 10
end
def second_last_digit(number)
(number.abs / 10) % 10
end
.....

Finished in 0.01294 seconds
5 examples, 0 failures
Малина Демирова
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Малина Демирова
def ordinalize(number)
if (number % 100) == 11 || (number % 100) == 12 || (number % 100) == 13
number.to_s + 'th'
elsif (number % 100) % 10 == 1
number.to_s + 'st'
elsif (number % 100) % 10 == 2
number.to_s + 'nd'
elsif (number % 100) % 10 == 3
number.to_s + 'rd'
else
number.to_s + 'th'
end
end
# Using case
# def ordinalize(number)
# ending = case number % 100
# when 11, 12, 13 then number.to_s + 'th'
# else
# case number % 10
# when 1 then number.to_s + 'st'
# when 2 then number.to_s + 'nd'
# when 3 then number.to_s + 'rd'
# else number.to_s + 'th'
# end
# end
# end
...FF

Failures:

  1) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1st"
            got: "-1th"
       
       (compared using ==)
     # /tmp/d20161027-13689-p91mpd/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-p91mpd/spec.rb:3:in `each'
     # /tmp/d20161027-13689-p91mpd/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-p91mpd/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with big numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1000000001st"
            got: "-1000000001th"
       
       (compared using ==)
     # /tmp/d20161027-13689-p91mpd/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-p91mpd/spec.rb:3:in `each'
     # /tmp/d20161027-13689-p91mpd/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-p91mpd/spec.rb:87:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00323 seconds
5 examples, 2 failures

Failed examples:

rspec /tmp/d20161027-13689-p91mpd/spec.rb:53 # #ordinalize works with negative numbers
rspec /tmp/d20161027-13689-p91mpd/spec.rb:86 # #ordinalize works with big numbers
Николина Гюрова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Николина Гюрова
def ordinalize(number)
suffix =
case number.to_s[-1].to_i
when 1 then 'st'
when 2 then 'nd'
when 3 then 'rd'
else 'th'
end
suffix = 'th' if number.to_s[-2].to_i == 1
number.to_s + suffix
end
.....

Finished in 0.00405 seconds
5 examples, 0 failures
Петър Велев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Велев
def ordinalize_positive number
if !(1..3).include?(number % 10) || (11..13).include?(number % 100)
"th"
else
case number % 10
when 1; "st"
when 2; "nd"
when 3; "rd"
end
end
end
def ordinalize number
number.to_s + ordinalize_positive(number.abs)
end
.....

Finished in 0.00338 seconds
5 examples, 0 failures
Дарин Тодоров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Дарин Тодоров
def ordinalize(number)
n = number.abs
if n % 100 == 11 || n % 100 == 12 || n % 100 == 13
number.to_s + 'th'
else
case n % 10
when 1
number.to_s + 'st'
when 2
number.to_s + 'nd'
when 3
number.to_s + 'rd'
else
number.to_s + 'th'
end
end
end
.....

Finished in 0.0033 seconds
5 examples, 0 failures
Момчил Баталов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Момчил Баталов
def ordinalize(number)
temp = number
if(temp<0)
temp =temp - 2*temp
end
last = temp % 10
pre_last = temp / 10 % 10
if (pre_last == 1 && (last == 1 || last == 2 || last == 3))
"#{number}th"
elsif (pre_last != 1 && last == 1)
"#{number}st"
elsif (pre_last != 1 && last == 2)
"#{number}nd"
elsif (pre_last != 1 && last == 3)
"#{number}rd"
else
"#{number}th"
end
end
.....

Finished in 0.00534 seconds
5 examples, 0 failures
Милен Дончев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Милен Дончев
def get_postfix(number)
postfixes = {1 => 'st', 2 => 'nd', 3 => 'rd'}
result = if number % 100 <= 10 || number % 100 >= 20 then postfixes[number % 10] end
result = (result.nil?) ? 'th' : result
result
end
def ordinalize(number)
is_negative = number < 0
number = is_negative ? number * (-1) : number
result = number.to_s + get_postfix(number)
result = is_negative ? ('-' + result) : result
result
end
.....

Finished in 0.00362 seconds
5 examples, 0 failures
Александър Илиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Илиев
def ordinalize(num)
additives = {
true => {'w/e' => 'th'},
false => {'1' => "st", '2' => 'nd', '3' => 'rd'}
}
num_s = num.to_s
num_s + additives[num_s.end_with?("11", "12", "13")].fetch(num_s[-1], 'th')
end
.....

Finished in 0.00442 seconds
5 examples, 0 failures
Беатрис Бонева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Беатрис Бонева
def ordinal(number)
abs_number = number.to_i.abs
if (11..13).include?(abs_number % 100)
"th"
else
case abs_number % 10
when 1 then "st"
when 2 then "nd"
when 3 then "rd"
else "th"
end
end
end
def ordinalize(number)
"#{number}#{ordinal(number)}"
end
.....

Finished in 0.00341 seconds
5 examples, 0 failures
Петър Скорчелиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Скорчелиев
def ordinalize(number)
number_string = number.to_s
suffixes = ['th', 'st', 'nd', 'rd']
endings_for_th = ['0', '11', '12', '13', '4', '5', '6', '7', '8', '9']
if number_string.end_with?(*endings_for_th)
number_string + suffixes[0]
else
number_string + suffixes[number.abs % 10]
end
end
.....

Finished in 0.00408 seconds
5 examples, 0 failures
Константин Димитров
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Константин Димитров
def ordinalize(number)
a = number.abs%10
number.to_s + ( a == 1 ? 'st' : a == 2 ? 'nd' : a == 3 ? 'rd' : 'th' )
end
F..F.

Failures:

  1) #ordinalize adds 'th' to the cardinal number in the common case
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "11th"
            got: "11st"
       
       (compared using ==)
     # /tmp/d20161027-13689-dho8pz/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-dho8pz/spec.rb:3:in `each'
     # /tmp/d20161027-13689-dho8pz/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-dho8pz/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-11th"
            got: "-11st"
       
       (compared using ==)
     # /tmp/d20161027-13689-dho8pz/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-dho8pz/spec.rb:3:in `each'
     # /tmp/d20161027-13689-dho8pz/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-dho8pz/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.0033 seconds
5 examples, 2 failures

Failed examples:

rspec /tmp/d20161027-13689-dho8pz/spec.rb:8 # #ordinalize adds 'th' to the cardinal number in the common case
rspec /tmp/d20161027-13689-dho8pz/spec.rb:53 # #ordinalize works with negative numbers
Методи Димитров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Методи Димитров
def ordinalize(number)
suffix = ((['th', 'st', 'nd', 'rd'] + ['th'] * 6) * 10).fill 'th', 11, 3
number.to_s + suffix[number.abs % 100]
end
.....

Finished in 0.00427 seconds
5 examples, 0 failures
Георги Иванов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Иванов
def ordinalize (number)
return "#{number}#{((number.abs / 10 % 10).equal?(1))? 'th' : {1 => 'st', 2 => 'nd', 3 => 'rd'}[number.abs % 10] || 'th'}"
end
.....

Finished in 0.00396 seconds
5 examples, 0 failures
Кузман Белев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Кузман Белев
SUFFIX = [*%w(th st nd rd), *%w(th)*10]
def ordinalize(number)
number.to_s + (SUFFIX[number.abs % 100] || SUFFIX[number.abs % 10])
end
.....

Finished in 0.00372 seconds
5 examples, 0 failures
Никола Жишев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Жишев
def ordinalize(number)
"#{number}#{ordinal(number)}"
end
def ordinal(number)
abs_number = number.abs
if (11..13).include?(abs_number % 100)
"th"
else
case abs_number % 10
when 1 then "st"
when 2 then "nd"
when 3 then "rd"
else "th"
end
end
end
.....

Finished in 0.00339 seconds
5 examples, 0 failures
Даниела Русева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Даниела Русева
def ordinalize(number)
number.to_s + if (number.abs % 10 == 1) & (((number.abs / 10) % 10) != 1)
'st'
elsif (number.abs % 10 == 2) & (((number.abs / 10) % 10) != 1)
'nd'
elsif (number.abs % 10 == 3) & (((number.abs / 10) % 10) != 1)
'rd'
else
'th'
end
end
.....

Finished in 0.00371 seconds
5 examples, 0 failures
Симеон Гергинов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Симеон Гергинов
def ordinalize(number)
if (11..13).include?(number.abs % 100)
"#{number}th"
else
case number.abs % 10
when 1 then "#{number}st"
when 2 then "#{number}nd"
when 3 then "#{number}rd"
else
"#{number}th"
end
end
end
.....

Finished in 0.00376 seconds
5 examples, 0 failures
Владимир Алексиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Владимир Алексиев
def ordinalize(number)
abs = number.to_i.abs
ordinal = if (11..13).include?(abs % 100)
"th"
else
case abs % 10
when 1 then "st"
when 2 then "nd"
when 3 then "rd"
else
"th"
end
end
"#{number}#{ordinal}"
end
.....

Finished in 0.00417 seconds
5 examples, 0 failures
Александър Ойнаков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Ойнаков
def ordinalize(number)
last_right_digit = "#{number}"[number.to_s.size - 1]
if number.to_s.size > 1
second_right_digit = "#{number}"[number.to_s.size - 2]
end
if last_right_digit.to_i.between?(1, 3) && second_right_digit.to_i != 1
case last_right_digit.to_i
when 1
"#{number}" + "st"
when 2
"#{number}" + "nd"
when 3
"#{number}" + "rd"
end
else
"#{number}" + "th"
end
end
.....

Finished in 0.00378 seconds
5 examples, 0 failures
Иван Станков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Станков
def ordinalize(number)
tail = (number <= -10 || number >= 10) ? number.to_s[-2..-1] : number.to_s[-1]
tail[-1] == '1' && tail != '11' && tail = 'st'
tail[-1] == '2' && tail != '12' && tail = 'nd'
tail[-1] == '3' && tail != '13' && tail = 'rd'
tail == 'st' || tail == 'nd' || tail == 'rd' || tail = 'th'
number.to_s + tail
end
.....

Finished in 0.00364 seconds
5 examples, 0 failures
Красимир Тренчев
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Красимир Тренчев
def ordinalize(number)
if (number/10)%10 == 1 then
suffix = "th"
else
suffix = "th" unless suffix = SUFFIXES[number % 10]
end
number.to_s << suffix
end
SUFFIXES = { 1 => "st", 2 => "nd", 3 => "rd"}
...FF

Failures:

  1) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1st"
            got: "-1th"
       
       (compared using ==)
     # /tmp/d20161027-13689-414q4c/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-414q4c/spec.rb:3:in `each'
     # /tmp/d20161027-13689-414q4c/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-414q4c/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with big numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1000000001st"
            got: "-1000000001th"
       
       (compared using ==)
     # /tmp/d20161027-13689-414q4c/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-414q4c/spec.rb:3:in `each'
     # /tmp/d20161027-13689-414q4c/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-414q4c/spec.rb:87:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00321 seconds
5 examples, 2 failures

Failed examples:

rspec /tmp/d20161027-13689-414q4c/spec.rb:53 # #ordinalize works with negative numbers
rspec /tmp/d20161027-13689-414q4c/spec.rb:86 # #ordinalize works with big numbers
Костадин Самарджиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Костадин Самарджиев
SUFFIXES = ['th', 'st', 'nd', 'rd']
def process_number number
last_digits = number % 100
if last_digits.between?(10,20)
"#{number}th"
elsif SUFFIXES[(last_digits % 10)]
"#{number}#{SUFFIXES[(last_digits % 10)]}"
else
"#{number}th"
end
end
def ordinalize(number)
case
when number.to_s.match(/-[0-9]*/)
"-#{process_number number.abs}"
when number.to_s.match(/[0-9]*/)
"#{process_number number.abs}"
end
end
.....

Finished in 0.00462 seconds
5 examples, 0 failures
Валентин Георгиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Валентин Георгиев
def ordinalize(number)
pos_number = number.abs
last_two_digits = pos_number % 100
case last_two_digits > 10 && last_two_digits < 14 ? last_two_digits : pos_number % 10
when 1
"#{number}st"
when 2
"#{number}nd"
when 3
"#{number}rd"
else
"#{number}th"
end
end
.....

Finished in 0.00326 seconds
5 examples, 0 failures
София Петрова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
София Петрова
def ordinalize(number)
case
when number.abs % 10 == 1 && number.to_s[-2..-1] != '11' then "#{number}st"
when number.abs % 10 == 2 && number.to_s[-2..-1] != '12' then "#{number}nd"
when number.abs % 10 == 3 && number.to_s[-2..-1] != '13' then "#{number}rd"
else "#{number}th"
end
end
.....

Finished in 0.00343 seconds
5 examples, 0 failures
Исмаил Алиджиков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Исмаил Алиджиков
def ordinalize(number)
"#{number}#{ordinal(number)}"
end
def ordinal(number)
abs_number = number.to_i.abs
if (11..13).include?(abs_number % 100)
"th"
else
case abs_number % 10
when 1; "st"
when 2; "nd"
when 3; "rd"
else "th"
end
end
end
.....

Finished in 0.00337 seconds
5 examples, 0 failures
Виктор Маринов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Маринов
FIRST_SUFFIX = "st"
SECOND_SUFFIX = "nd"
THIRD_SUFFIX = "rd"
DEFAULT_SUFFIX = "th"
def ordinalize(number)
abs_number = number.to_i.abs
suffix =
if (11..13).include?(abs_number % 100)
DEFAULT_SUFFIX
else
case abs_number % 10
when 1 then FIRST_SUFFIX
when 2 then SECOND_SUFFIX
when 3 then THIRD_SUFFIX
else DEFAULT_SUFFIX
end
end
number.to_s + suffix
end
.....

Finished in 0.00333 seconds
5 examples, 0 failures
Константин Нецов
  • Некоректно
  • 2 успешни тест(а)
  • 3 неуспешни тест(а)
Константин Нецов
def ordinalize(number)
return nil unless number.is_a?(Integer)
h = {1 => "st", 2 => "nd", 3 => "rd"}
h.default = "th"
(number / 10 == 1) ? "#{number}th" : "#{number}#{h[number % 10]}"
end
F..FF

Failures:

  1) #ordinalize adds 'th' to the cardinal number in the common case
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "111th"
            got: "111st"
       
       (compared using ==)
     # /tmp/d20161027-13689-apse0q/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-apse0q/spec.rb:3:in `each'
     # /tmp/d20161027-13689-apse0q/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-apse0q/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1st"
            got: "-1th"
       
       (compared using ==)
     # /tmp/d20161027-13689-apse0q/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-apse0q/spec.rb:3:in `each'
     # /tmp/d20161027-13689-apse0q/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-apse0q/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  3) #ordinalize works with big numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1000000001st"
            got: "-1000000001th"
       
       (compared using ==)
     # /tmp/d20161027-13689-apse0q/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-apse0q/spec.rb:3:in `each'
     # /tmp/d20161027-13689-apse0q/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-apse0q/spec.rb:87:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00334 seconds
5 examples, 3 failures

Failed examples:

rspec /tmp/d20161027-13689-apse0q/spec.rb:8 # #ordinalize adds 'th' to the cardinal number in the common case
rspec /tmp/d20161027-13689-apse0q/spec.rb:53 # #ordinalize works with negative numbers
rspec /tmp/d20161027-13689-apse0q/spec.rb:86 # #ordinalize works with big numbers
Михаил Здравков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Михаил Здравков
def ordinalize(number)
case
when number.to_s.match(/(^|.*[^1])1\z/) then number.to_s + 'st'
when number.to_s.match(/(^|.*[^1])2\z/) then number.to_s + 'nd'
when number.to_s.match(/(^|.*[^1])3\z/) then number.to_s + 'rd'
else number.to_s + 'th'
end
end
.....

Finished in 0.00382 seconds
5 examples, 0 failures
Цветан Христов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Христов
def ordinalize(number)
last_number = number.abs % 100
number.to_s <<
if [11, 12, 13].include? last_number
'th'
elsif last_number % 10 == 1
'st'
elsif last_number % 10 == 2
'nd'
elsif last_number % 10 == 3
'rd'
else
'th'
end
end
.....

Finished in 0.00333 seconds
5 examples, 0 failures
Теодор Филипов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Филипов
def ordinalize(number)
ending = 'st' if (number.to_s.end_with? '1') && !(number.to_s.end_with? '11')
ending = 'nd' if (number.to_s.end_with? '2') && !(number.to_s.end_with? '12')
ending = 'rd' if (number.to_s.end_with? '3') && !(number.to_s.end_with? '13')
ending = 'th' if ending.nil?
number.to_s + ending
end
.....

Finished in 0.00409 seconds
5 examples, 0 failures
Иво Яков
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Иво Яков
EXC = { 11 => 'th', 12 => 'th', 13 => 'th', 1 => 'st', 2 => 'nd', 3 => 'rd' }
def ordinalize(number)
number.to_s +
if EXC.key? number.abs % 100
EXC[number.abs % 100]
elsif EXC.key? number.abs % 10
EXC[number.abs % 10]
else 'th'
end
end
.....

Finished in 0.00333 seconds
5 examples, 0 failures
Кристъфър Коруев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Кристъфър Коруев
def ordinalize(number)
last_digit = number.to_s[-1, 1]
return number.to_s + 'th' if number.to_s[-2, 1] == '1'
case last_digit
when '1' then number.to_s + 'st'
when '2' then number.to_s + 'nd'
when '3' then number.to_s + 'rd'
else number.to_s + 'th'
end
end
.....

Finished in 0.00348 seconds
5 examples, 0 failures
Антон Сотиров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Антон Сотиров
def ordinalize(number)
if (11..13).cover?(number.abs % 100)
"#{number}th"
else
case number.abs % 10
when 1 then "#{number}st"
when 2 then "#{number}nd"
when 3 then "#{number}rd"
else "#{number}th"
end
end
end
.....

Finished in 0.0033 seconds
5 examples, 0 failures
Васил Чимев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Васил Чимев
def ordinalize(number)
custom = { '1' => 'st', '2' => 'nd', '3' => 'rd' }
number_s = number.to_s
number_chars = number_s.chars
result = if (custom.key? number_chars[-1]) && (number_chars[-2] != '1')
number_s + custom[number_chars[-1]]
else
number_s + 'th'
end
result
end
.....

Finished in 0.00373 seconds
5 examples, 0 failures
Калоян Евтимов
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Калоян Евтимов
UP_TO_NINETEEN = [
'th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th',
'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th'
]
DIGIT_SUF = {
1 => 'st',
2 => 'nd',
3 => 'rd'
}
def ordinalize(number)
abs_n = number.abs
if number.abs <= 19
number.to_s + UP_TO_NINETEEN[abs_n]
else
number.to_s + DIGIT_SUF.fetch(abs_n % 10, 'th')
end
end
F..F.

Failures:

  1) #ordinalize adds 'th' to the cardinal number in the common case
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "111th"
            got: "111st"
       
       (compared using ==)
     # /tmp/d20161027-13689-3ngmyc/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-3ngmyc/spec.rb:3:in `each'
     # /tmp/d20161027-13689-3ngmyc/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-3ngmyc/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-111th"
            got: "-111st"
       
       (compared using ==)
     # /tmp/d20161027-13689-3ngmyc/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-3ngmyc/spec.rb:3:in `each'
     # /tmp/d20161027-13689-3ngmyc/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-3ngmyc/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00341 seconds
5 examples, 2 failures

Failed examples:

rspec /tmp/d20161027-13689-3ngmyc/spec.rb:8 # #ordinalize adds 'th' to the cardinal number in the common case
rspec /tmp/d20161027-13689-3ngmyc/spec.rb:53 # #ordinalize works with negative numbers
Мая Терзиева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Мая Терзиева
def ordinalize(number)
pattern_found = ['13th', '12th', '11th', '3rd', '2nd', '1st']
.find { |pattern| number.to_s.end_with? pattern[0..-3] }
pattern_found ? "#{number}#{pattern_found[-2..-1]}" : "#{number}th"
end
.....

Finished in 0.00411 seconds
5 examples, 0 failures
Богомила Пенева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Богомила Пенева
def ordinalize(number)
if (number.abs % 100) / 10 == 1
number.to_s + 'th'
elsif number.abs % 10 == 1
number.to_s + 'st'
elsif number.abs % 10 == 2
number.to_s + 'nd'
elsif number.abs % 10 == 3
number.to_s + 'rd'
else
number.to_s + 'th'
end
end
.....

Finished in 0.00338 seconds
5 examples, 0 failures
Добромира Лозева
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Добромира Лозева
def ordinalize(n)
if n < 0
n *= -1
m = '-'
end
m.to_s + n.to_s + %w{th st nd rd} [ ((n / 10 % 10 == 1) || (n % 10 > 3)) ? 0 : n % 10 ]
end
.....

Finished in 0.00351 seconds
5 examples, 0 failures
Йордан Иванов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Йордан Иванов
def ordinalize(number)
if (1..3).include?(number.abs%10) && !(11..13).include?(number.abs%100)
number.to_s + %w{st nd rd}[number.abs%10-1]
else
number.to_s + 'th'
end
end
.....

Finished in 0.0034 seconds
5 examples, 0 failures
Христо Кирилов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Кирилов
def ordinal(number)
return 'th' if number.abs % 100 / 10 == 1
case number.abs % 10
when 1
'st'
when 2
'nd'
when 3
'rd'
else
'th'
end
end
def ordinalize(number)
number.to_s + ordinal(number)
end
.....

Finished in 0.03392 seconds
5 examples, 0 failures
Делян Лафчиев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Делян Лафчиев
def ordinalize(number)
absmod10 = number.abs.modulo(10)
absmod100 = number.abs.modulo(100)
number.to_s + ((absmod100 >= 11 && absmod100 <= 20) ? 'th' : absmod10 == 1 ? 'st' : absmod10 == 2 ? 'nd' : absmod10 == 3 ? 'rd' : 'th')
end
.....

Finished in 0.00703 seconds
5 examples, 0 failures
Георги Карапетров
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Георги Карапетров
def suffix_for_digit(digit)
case digit
when 1
'st'
when 2
'nd'
when 3
'rd'
else
'th'
end
end
def suffix_for(number)
return 'th' if number.abs.between?(11, 13)
last_digit = number.abs.between?(0, 9) ? number.abs : number.abs % 10
suffix_for_digit(last_digit)
end
def ordinalize(number)
"#{number}#{suffix_for(number)}"
end
F..F.

Failures:

  1) #ordinalize adds 'th' to the cardinal number in the common case
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "111th"
            got: "111st"
       
       (compared using ==)
     # /tmp/d20161027-13689-6ov38h/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-6ov38h/spec.rb:3:in `each'
     # /tmp/d20161027-13689-6ov38h/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-6ov38h/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-111th"
            got: "-111st"
       
       (compared using ==)
     # /tmp/d20161027-13689-6ov38h/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-6ov38h/spec.rb:3:in `each'
     # /tmp/d20161027-13689-6ov38h/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-6ov38h/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00351 seconds
5 examples, 2 failures

Failed examples:

rspec /tmp/d20161027-13689-6ov38h/spec.rb:8 # #ordinalize adds 'th' to the cardinal number in the common case
rspec /tmp/d20161027-13689-6ov38h/spec.rb:53 # #ordinalize works with negative numbers
Натали Арабаджийска
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Натали Арабаджийска
def ordinalize(number)
if number.abs%10 == 1 && (number.abs/10)%10 != 1
number.to_s + "st"
elsif number.abs%10 == 2 && (number.abs/10)%10 != 1
number.to_s + "nd"
elsif number.abs%10 == 3 && (number.abs/10)%10 != 1
number.to_s + "rd"
else
number.to_s + "th"
end
end
.....

Finished in 0.00336 seconds
5 examples, 0 failures
Станислав Димитров
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Станислав Димитров
def ordinalize(number)
number > 0 ? add_suff(number.abs) : add_suff(number)
end
def add_suff(number)
second_num = number % 100
first_num = number % 10
if (1..3).member?(first_num) && !(11..13).include?(second_num)
"#{number.to_s}#{%w{st nd rd}[first_num-1]}"
else
"#{number.to_s}th"
end
end
...FF

Failures:

  1) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1st"
            got: "-1th"
       
       (compared using ==)
     # /tmp/d20161027-13689-p2ttyu/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-p2ttyu/spec.rb:3:in `each'
     # /tmp/d20161027-13689-p2ttyu/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-p2ttyu/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with big numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-1000000001st"
            got: "-1000000001th"
       
       (compared using ==)
     # /tmp/d20161027-13689-p2ttyu/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-p2ttyu/spec.rb:3:in `each'
     # /tmp/d20161027-13689-p2ttyu/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-p2ttyu/spec.rb:87:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00326 seconds
5 examples, 2 failures

Failed examples:

rspec /tmp/d20161027-13689-p2ttyu/spec.rb:53 # #ordinalize works with negative numbers
rspec /tmp/d20161027-13689-p2ttyu/spec.rb:86 # #ordinalize works with big numbers
Теодора Петкова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Теодора Петкова
def ordinalize(number)
final_two_digits = number.abs - (number.abs / 100 * 100)
case final_two_digits
when 11, 12, 13
number.to_s + "th"
else
final_digit = number.abs - (number.abs / 10 * 10)
case final_digit
when 1
number.to_s + "st"
when 2
number.to_s + "nd"
when 3
number.to_s + "rd"
when 0, 4..9
number.to_s + "th"
end
end
end
.....

Finished in 0.0034 seconds
5 examples, 0 failures
Стоян Томицин
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Томицин
def ordinalize( number )
if number.abs % 100 == 11 || number.abs % 100 == 12 || number.abs % 100 == 13
number.to_s + 'th'
elsif number.abs % 10 == 1
number.to_s + 'st'
elsif number.abs % 10 == 2
number.to_s + 'nd'
elsif number.abs % 10 == 3
number.to_s + 'rd'
else
number.to_s + 'th'
end
end
.....

Finished in 0.00336 seconds
5 examples, 0 failures
Стамен Драгоев
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Стамен Драгоев
def ordinalize(number)
last_digit = number.to_s[-1].to_i
number_of_digits = number.abs.to_s.size
digit_of_dec = 0
digit_of_dec = number.to_s[-2].to_i if number_of_digits >= 2
special_numbers = [11, 12, 13]
is_special = special_numbers.include?(digit_of_dec * 10 + last_digit)
if last_digit == 1 && !is_special
number.to_s << "st"
elsif last_digit == 2 && !is_special
number.to_s << "nd"
elsif last_digit == 3 && !is_special
number.to_s << "rd"
else
number.to_s << "th"
end
end
.....

Finished in 0.00363 seconds
5 examples, 0 failures
Елеонора Кайкова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Елеонора Кайкова
def ordinalize(number)
result = number.to_s
result + if (11..13).include?(number.abs % 100)
'th'
else
case number.abs % 10
when 1
'st'
when 2
'nd'
when 3
'rd'
else
'th'
end
end
end
.....

Finished in 0.00339 seconds
5 examples, 0 failures
Сияна Плачкова
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Сияна Плачкова
def ordinalize(number)
last_digit = number.abs % 10
last_two_digits = number.abs % 100
number.to_s <<
if (1..3).include?(last_digit) && !(11..13).include?(last_two_digits)
%w{st nd rd}[last_digit - 1]
else
'th'
end
end
.....

Finished in 0.00338 seconds
5 examples, 0 failures
Стефан Якимов
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Стефан Якимов
def ordinalize(num)
surplus = num.abs % 10
num.to_s + if surplus == 1
'st'
elsif surplus == 2
'nd'
elsif surplus == 3
'rd'
else
'th'
end
end
F..F.

Failures:

  1) #ordinalize adds 'th' to the cardinal number in the common case
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "11th"
            got: "11st"
       
       (compared using ==)
     # /tmp/d20161027-13689-1ctk44j/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-1ctk44j/spec.rb:3:in `each'
     # /tmp/d20161027-13689-1ctk44j/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-1ctk44j/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-11th"
            got: "-11st"
       
       (compared using ==)
     # /tmp/d20161027-13689-1ctk44j/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-1ctk44j/spec.rb:3:in `each'
     # /tmp/d20161027-13689-1ctk44j/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-1ctk44j/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00326 seconds
5 examples, 2 failures

Failed examples:

rspec /tmp/d20161027-13689-1ctk44j/spec.rb:8 # #ordinalize adds 'th' to the cardinal number in the common case
rspec /tmp/d20161027-13689-1ctk44j/spec.rb:53 # #ordinalize works with negative numbers
Виктор Клисуров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Клисуров
def ordinalize(number)
if (11..13).include? number.abs % 100
"#{number}th"
else
case number.abs % 10
when 1 then "#{number}st"
when 2 then "#{number}nd"
when 3 then "#{number}rd"
else "#{number}th"
end
end
end
.....

Finished in 0.00332 seconds
5 examples, 0 failures
Радослав Гайдаров
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Радослав Гайдаров
def ordinalize(number)
clone = number.abs
clone %= 100 if clone > 99
clone %= 10 if clone > 19
case clone
when 1 then "#{number}st"
when 2 then "#{number}nd"
when 3 then "#{number}rd"
when 0, (4..19) then "#{number}th"
end
end
.....

Finished in 0.00336 seconds
5 examples, 0 failures
Ивайло Дончев
  • Некоректно
  • 3 успешни тест(а)
  • 2 неуспешни тест(а)
Ивайло Дончев
def ordinalize(num)
stringified_num = num.to_s
last_number = stringified_num[-1]
if last_number == '1'
stringified_num + 'st'
elsif last_number == '2'
stringified_num + 'nd'
elsif last_number == '3'
stringified_num + 'rd'
else
stringified_num + 'th'
end
end
F..F.

Failures:

  1) #ordinalize adds 'th' to the cardinal number in the common case
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "11th"
            got: "11st"
       
       (compared using ==)
     # /tmp/d20161027-13689-avlmmo/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-avlmmo/spec.rb:3:in `each'
     # /tmp/d20161027-13689-avlmmo/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-avlmmo/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #ordinalize works with negative numbers
     Failure/Error: expect(ordinalize(number)).to eq ordinalized
       
       expected: "-11th"
            got: "-11st"
       
       (compared using ==)
     # /tmp/d20161027-13689-avlmmo/spec.rb:4:in `block in expect_transformations'
     # /tmp/d20161027-13689-avlmmo/spec.rb:3:in `each'
     # /tmp/d20161027-13689-avlmmo/spec.rb:3:in `expect_transformations'
     # /tmp/d20161027-13689-avlmmo/spec.rb:54:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00334 seconds
5 examples, 2 failures

Failed examples:

rspec /tmp/d20161027-13689-avlmmo/spec.rb:8 # #ordinalize adds 'th' to the cardinal number in the common case
rspec /tmp/d20161027-13689-avlmmo/spec.rb:53 # #ordinalize works with negative numbers
Никола Младенов
  • Коректно
  • 5 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Младенов
def ordinalize(number)
string = number.to_s
string << if string[-2, 2] == '11' ||
string[-2, 2] == '12' ||
string[-2, 2] == '13'
"th"
elsif string[-1] == '1'
"st"
elsif string[-1] == '2'
"nd"
elsif string[-1] == '3'
"rd"
else
"th"
end
end
.....

Finished in 0.00356 seconds
5 examples, 0 failures