Skip to content

Instantly share code, notes, and snippets.

View ashwinvidiyala's full-sized avatar

Ashwin Vidiyala ashwinvidiyala

View GitHub Profile
for i in 1..100
puts i if i % 2 != 0
end
@ashwinvidiyala
ashwinvidiyala / flatten.rb
Created April 8, 2018 22:25
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers
class Flatten
def self.flatten input, answer = []
# Function is called recursively if element of input is an Array.
# If element is not an Array, it is pushed to answer.
input.each do |element|
element.is_a?(Array) ? self.flatten(element, answer) : answer << element
end
answer
end
end