Ruby 初心者スレッド Part 32
■ このスレッドは過去ログ倉庫に格納されています
0752デフォルトの名無しさん
2009/11/26(木) 00:19:34まあそんなとこだろうな
処理全部自前だからめんどくさいが
class Array
def slice2(index, length, stride)
res = Array.new
self.each_with_index do |e, i|
res << e if ((index <= i) && (res.size < length) && ((i - index) % stride).zero?)
end
res
end
end
p ["a", "b", "c", "d", "e", "f"].slice2(0,3,2) #=> ["a", "c", "e"]
p ["a", "b", "c", "d", "e", "f"].slice2(3,2,1) #=> ["d", "e"]
ていうかそもそもこれでいいのか? なんか需要違わね?
■ このスレッドは過去ログ倉庫に格納されています