对于每个单词,我试图将单词的第一个字母移动到单词的末尾.例如,
"this is an example"----> "hist si na xamplee".例如,我用一个词实现了这个目标,
x = "hello"
x << x.split("").shift # => "elloh"
Run Code Online (Sandbox Code Playgroud)
"this is an example".gsub(/(\S)(\S+)/, '\2\1')
# => "hist si na xamplee"
Run Code Online (Sandbox Code Playgroud)
'this is an example'.split.map { |word| word.chars.rotate.join }.join(' ')
#=> "hist si na xamplee"
Run Code Online (Sandbox Code Playgroud)
参考:
| 归档时间: |
|
| 查看次数: |
183 次 |
| 最近记录: |