lib/picky/extensions/array.rb in picky-0.9.3 vs lib/picky/extensions/array.rb in picky-0.9.4
- old
+ new
@@ -10,9 +10,24 @@
self.inject([]) do |result, element|
result << element if element != result.last
result
end
end
+ # Around 10% faster than the above.
+ #
+ # Returns a copy.
+ #
+ def clustered_uniq_fast
+ result = []
+ self.inject(nil) do |last, element|
+ if last == element
+ last
+ else
+ result << element && element
+ end
+ end
+ result
+ end
# Accesses a random element of this array.
#
# TODO Remove?
#
\ No newline at end of file