Created
April 17, 2015 22:30
-
-
Save kungfumike/7b767142d07817e19045 to your computer and use it in GitHub Desktop.
5 years ago vs today
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 5 years ago..... | |
if first.nil? | |
first_non_nil = compact.first | |
each_with_index{|val, i| | |
break if val | |
self[i] = first_non_nil | |
} | |
end | |
# Forwardfill | |
if last.nil? | |
last_non_nil = compact.last | |
reverse!.each_with_index{|val, i| | |
break if val | |
self[i] = last_non_nil | |
} | |
reverse! | |
end | |
# Re-factoring today... | |
self[0] = find_all {|x| !x.nil?}.first if first.nil? | |
self[(size - 1)] = find_all {|x| !x.nil?}.last if last.nil? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment