2012-02-08 3 views

答えて

10

あなたはこのアプローチを試すことができます。

def repeat(input, n) 
    ([input] * n).join ' ' 
end 
+0

素晴らしい、感謝 – mehulkar

7

シンプル、

def repeat(input, n) 
    ("#{input} " * n).strip 
end 
+0

ナイス! stripメソッドは、先頭と末尾の空白を削除します。 –

3
def repeat(input, n) 
    Array.new(n, input).join ' ' 
end 
関連する問題