Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
array utils, will be used in toc extraction. uniq would not work; som…
…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
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |