Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Array
- def custom_flatten
- flattened = []
- each do |elem|
- flattened += elem.is_a?(Array) ? elem.custom_flatten : [elem]
- end
- flattened
- end
- end
- RSpec Array
- describe "#custom_flatten"
- let(:ar) { [1,2, [3,4, 5], 5] }
- it "flattens the array into a single one" do
- expect(ar.custom_flatten).to eq([1,2,3,4,5,5])
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement