Skip to content
Browse files

added array_ext.rb

  • Loading branch information...
1 parent 4b5d8b0 commit bbb9c1afa5a48f8c1f99e29728f7cb648801bdb1 @michaelfeathers committed May 16, 2011
Showing with 23 additions and 0 deletions.
  1. +23 −0 array_ext.rb
View
23 array_ext.rb
@@ -0,0 +1,23 @@
+
+
+class Array
+
+ def date_sorted
+ sort { |left,right| left.date <=> right.date }
+ end
+
+ def transitions
+ each_cons(2).to_a
+ end
+
+ def freq
+ groups = group_by { |value| value }
+ (0..(max || -1)).map { |bin| groups.fetch(bin, []).count }
+ end
+
+ def convolve filter_function
+ window_size = method(filter_function).arity
+ each_cons(window_size).map { |window| send(filter_function, *window) }
+ end
+end
+

0 comments on commit bbb9c1a

Please sign in to comment.
Something went wrong with that request. Please try again.