Class: Array
- Defined in:
- lib/lab419/core/array/flatten_once.rb,
lib/lab419/core/array/without_indices.rb
Instance Method Summary collapse
Instance Method Details
#flatten_once ⇒ Object
2 3 4 |
# File 'lib/lab419/core/array/flatten_once.rb', line 2 def flatten_once inject([]){ |a,e| [*a] + [*e] } end |
#without_indices(*indices) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/lab419/core/array/without_indices.rb', line 2 def without_indices *indices s = size indices = indices.map{ |x| x < 0 ? s + x : x }.uniq.reject{ |x| x >=s || x < 0 }.sort return dup if indices.empty? prefix = indices.inject [[],0] do |(a, li), i| [ a + (self[li, [i-li,0].max] || []), i.succ ] end.first prefix + ( self[indices.last.succ..-1] || [] ) end |