Skip to content

Commit

Permalink
Merge pull request #3 from msuliq/feat/flatten-optimizations
Browse files Browse the repository at this point in the history
Feat/flatten optimizations
  • Loading branch information
msuliq committed May 6, 2023
2 parents d404700 + c0a8ace commit 1206212
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
## [Released]

## [0.1.0] - 2023-04-15
- Initial release

## [0.1.4] - 2023-05-06
- Improvements related to .flatten method, fixing typos
## [0.1.3] - 2023-04-15
- Templates added for PR's, bug reports and feature requests
## [0.1.2] - 2023-04-15
- Improvements to CI workflow
## [0.1.1] - 2023-04-15
- Fixes for broken links
- Updates to CI workflow
## [0.1.0] - 2023-04-15
- Initial release

## [0.1.2] - 2023-04-15
- Improvements to CI workflow

## [0.1.3] - 2023-04-16
- Templates added for PR's, bug reports and feature requests
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
distributed_merge (0.1.3)
distributed_merge (0.1.4)

GEM
remote: https://rubygems.org/
Expand Down
6 changes: 4 additions & 2 deletions lib/distributed_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module DistributedMergeArray # :nodoc:
# Accepts a two-dimensional array with subarrays of varying size and returns
# merged array with the elements distributed across.
def distributed_merge
return self unless two_dimensional?
raise ArgumentError, "Input must be an array of arrays" unless two_dimensional?

data = sort_arrays_by_size
largest = data.first
Expand All @@ -44,7 +44,9 @@ def distributed_merge
def two_dimensional?
return false unless all_arrays?

flatten(1).none? { |arg| arg.instance_of?(Array) } && flatten(1).count > 1
flattened_array = flatten(1)

flattened_array.none? { |arg| arg.instance_of?(Array) } && flattened_array.count > 1
end

def all_arrays?
Expand Down
2 changes: 1 addition & 1 deletion lib/distributed_merge/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DistributedMerge
VERSION = "0.1.3"
VERSION = "0.1.4"
end
6 changes: 3 additions & 3 deletions test/test_distributed_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def test_raises_no_method_error
assert_raises(NoMethodError) { hash.distributed_merge }
end

def test_returns_original_array_if_not_two_dimensional
def test_raises_argument_error_if_not_two_dimensional
one_d = [1, 2, 3, 4, 5]
assert_equal one_d, one_d.distributed_merge
assert_raises(ArgumentError) { one_d.distributed_merge }

three_d = [[[1, 2, 3], [4, 5]], [6, 7, 8, 9, 10]]
assert_equal three_d, three_d.distributed_merge
assert_raises(ArgumentError) { three_d.distributed_merge }
end

def test_case_10_vs_1_array
Expand Down

0 comments on commit 1206212

Please sign in to comment.