- Коректно
- 4 успешни тест(а)
- 0 неуспешни тест(а)
class Polynomial
  def initialize(polynomial)
    @polynomial = polynomial
  end
  def to_s
    polynomial_string = ""
    reversal = @polynomial.length - 1
    @polynomial.each_with_index do |element, index|
      x = "x"
      sign = "+ "
      power = reversal - index
      coefficient = ""
      string_power = ""
      case power
        when 0
          string_power = ""
          x = ""
        when 1
          string_power = " "
        else
          string_power = "^" + power.to_s + " "
      end
      if element < -1
        sign = "- "
        coefficient = element.abs.to_s
      elsif element == -1 and power != 0
        sign = "- "
      elsif element == -1 and power == 0
        sign = "- "
        coefficient = element.abs.to_s
      elsif element == 0 and power != 0
        sign, x, string_power = "", "", ""
      elsif element == 1 and power != 0
        coefficient = ""
      elsif element == 0 and power == 0
        coefficient = element.to_s
        sign = ""
      else
        coefficient = element.to_s
      end
      polynomial_string += sign + coefficient + x + string_power
    end
    polynomial_string[0] == "+" ? polynomial_string.slice(2..-1).chomp(" 0") : polynomial_string.chomp(" 0")
  end
end
.... Finished in 0.12504 seconds 4 examples, 0 failures



































