Created
November 19, 2013 23:42
-
-
Save mikewadhera/7554629 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# [] #=> [] | |
# [:a] #=> [] | |
# [:a, :b] #=> [:a] or [:b] | |
# [:a, :b, :c] #=> [:a, :b] or [:b, :c] or [:a, :c] | |
# [:a, :b, :c, :d] #=> [:b, :c] or [:a, :c] or [:b, :d] or [:c, :d] | |
def recommend_siblings_for(item, list) | |
case list.size | |
when 0,1 | |
[] | |
else | |
i = list.at(item) | |
case i | |
when nil | |
[] | |
when 0 # head | |
list[1..2] | |
when list.length - 1 # tail | |
# TODO | |
else # interior | |
[list[i-1], list[i+1]] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment