Skip to content

Instantly share code, notes, and snippets.

@rosylilly
Created April 19, 2010 14:01
Show Gist options
  • Save rosylilly/371074 to your computer and use it in GitHub Desktop.
Save rosylilly/371074 to your computer and use it in GitHub Desktop.
class Array
def nindex(n)
p self
_index = self.index(n)
if _index.nil?
return []
else
if _index == (self.size - 1)
return [_index]
else
return [
_index,
self[_index+1 ... self.size].nindex(n).map{|i| i+_index+1}
].flatten
end
end
end
end
p [1, 2, 3, 4, 5, 3].nindex(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment