Skip to content

Commit

Permalink
array utils, will be used in toc extraction. uniq would not work; som…
Browse files Browse the repository at this point in the history
…etimes the same header gets re-used later on in the same day
  • Loading branch information
Daniel Haran committed Apr 15, 2009
1 parent f9052c7 commit cd8b84b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions array_utils.rb
@@ -0,0 +1,12 @@
class ArrayUtils
class << self
def firsts_in_sequence(elements)
first = nil
elements.select do |cur|
ret = (cur != first)
first = cur
ret
end
end
end
end
8 changes: 8 additions & 0 deletions test/array_utils_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'
require '../array_utils'

class ArrayUtilsTest < Test::Unit::TestCase
def test_firsts_in_sequence
assert_equal [1,2,1,2,3], ArrayUtils.firsts_in_sequence([1,1,1,1,2,1,1,1,2,2,2,2,2,2,2,3,3])
end
end

0 comments on commit cd8b84b

Please sign in to comment.