Skip to content

Instantly share code, notes, and snippets.

@mikewadhera
Created November 19, 2013 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikewadhera/7554629 to your computer and use it in GitHub Desktop.
Save mikewadhera/7554629 to your computer and use it in GitHub Desktop.
# [] #=> []
# [: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