Created
July 20, 2019 01:26
-
-
Save netmask/c0a7e7b1e8f221d44e473569ae2f64ac to your computer and use it in GitHub Desktop.
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
require "minitest/autorun" | |
module ArrayTools | |
refine Array do | |
def flatt | |
reduce([]) do |new_array, el| | |
if el.instance_of? Array | |
new_array += el.flatt | |
else | |
new_array << el | |
end | |
end | |
end | |
end | |
end | |
class TestArrayTools < Minitest::Test | |
using ArrayTools | |
def test_flatt | |
assert_equal [1,2,3,4], [[[1,2,[3]],4]].flatt | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment