Skip to content

Instantly share code, notes, and snippets.

@albertein
Last active January 2, 2016 15:49
Show Gist options
  • Save albertein/8325947 to your computer and use it in GitHub Desktop.
Save albertein/8325947 to your computer and use it in GitHub Desktop.
def merge(l1, l2)
out = []
while(!(l1.empty? && l2.empty?)) do
list = nil
if (l2.empty? || l1[0].timestamp < l2[0].timestamp)
list = l1
else
list = l2
end
element = list.slice!(0)
last = out.last
if (!last.nil? && last.timestamp == element.timestamp)
last.value += element.value
else
out << element
end
end
out
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment