Skip to content

Instantly share code, notes, and snippets.

View juanfurattini's full-sized avatar

Juan Manuel Furattini juanfurattini

View GitHub Profile
@juanfurattini
juanfurattini / codility_missing_number.rb
Last active July 26, 2018 05:20
Solution for Codility's MissingInteger exercise with a score of 100% (Ruby)
def solution(a)
val = 0
a.uniq.sort.each do |e|
next if e <= 0
return val.next if e > val.next
val = e
end
val.next
end
@juanfurattini
juanfurattini / array_flattener.rb
Last active July 26, 2018 06:22
Flattens an Array without using the built-in Array#flatten method (For testing it requires spec)
module ArrayUtils
extend self
# Converts a nested array to a flatten array without using the built-in method Array#flatten
# It doesn't remove nil
#
# If the passed parameter is not an array, the same object is returned
# to_flat_array(nil) #=> nil
# to_flat_array({ a: 'something }) #=> {:a=>"something"}
# If the passed parameter is a nested array, a flatten array is returned