Skip to content

Instantly share code, notes, and snippets.

View felipero's full-sized avatar
🐞
Debugging

Felipe Rodrigues felipero

🐞
Debugging
View GitHub Profile
class ArrayTools
def self.flat_array(array = [])
array.each_with_object([]) do |item, flat_array|
next if item.kind_of? String
flat_array.push *(item.kind_of?(Array) ? flat_array(item) : item)
end
end
end
class BracketsChecker
OPENING = ['[', '{', '(']
CLOSING_MAP = {'[' => ']', '{' => '}', '(' => ')'}
def valid?(input)
return false if input.empty?
open_brackets = []
input.each_char do |char|
open_brackets << char if OPENING.include? char