Conditionals

Краплі дощу
Краплі дощу у треку Crystal
module Raindrops
  def self.convert(count : Int32) : String
    result = ""
    result += "Pling" if count.divisible_by?(3)
    result += "Plang" if count.divisible_by?(5)
    result += "Plong" if count.divisible_by?(7)
    result.empty? ? count.to_s : result
  end
end

This approach uses a series of if's suffix statements to build a string. It starts by creating an empty String. Then based on if the number is divisible by 3, 5, or 7, it adds the appropriate string to the result. The String added needs to be added in the correct order, otherwise the result would be reversed. Finally, if the result is empty, it returns the number as a String, otherwise it returns the result. It uses implicit return to return the result.

Translation missing: uk.number.nth.ordinalized Sep 2026 · Це було корисно?

Інші підходи до вправи Краплі дощу у треку Crystal

Інші способи, якими наша спільнота розвʼязала цю вправу