将每个单词的第一个字母附加到末尾

Ben*_*nts -2 ruby

对于每个单词,我试图将单词的第一个字母移动到单词的末尾.例如,

  • "this is an example"----> "hist si na xamplee".

例如,我用一个词实现了这个目标,

x = "hello"
x << x.split("").shift # => "elloh"
Run Code Online (Sandbox Code Playgroud)

saw*_*awa 6

"this is an example".gsub(/(\S)(\S+)/, '\2\1')
# => "hist si na xamplee"
Run Code Online (Sandbox Code Playgroud)


And*_*eko 5

'this is an example'.split.map { |word| word.chars.rotate.join }.join(' ')
#=> "hist si na xamplee"
Run Code Online (Sandbox Code Playgroud)

参考: