我的代码在这里
str = "Early in his first term in office, Obama signed into law economic stimulus legislation in response"
arr= str.split(" ")
set_element= arr.each_cons(2).to_a
sub_str = set_element.map {|i| i.join(' ')}
如果我有一个很大的字符串,比如非常大的字符串,那么这个过程需要 6.50 秒,因为我想要这种类型的结果
sub_str= ["Early in", "in his", "his first", "first term", "term in", "in office,", "office, Obama", "Obama signed", "signed into", "into law", "law economic", "economic stimulus", "stimulus legislation", "legislation in", "in response"]
是否有可能以有效的方式进行任何其他方式