Skip to content

Instantly share code, notes, and snippets.

View thirdtruck's full-sized avatar

Jaycie Holder thirdtruck

View GitHub Profile
@thirdtruck
thirdtruck / flatten.rb
Last active March 16, 2017 00:09
Flatten an Array
require 'minitest/autorun'
def count_all_elements(array)
element_count = 0
array.each do |el|
# Given Ruby's duck-typing, it makes more sense to check for iterable
# objects than for integer-like objects. Otherwise we'd do more
# thorough type-checking.
if el.respond_to? :each