simple-exercises/ruby-exercises/easy-4.rb
# Two Degrees of Separation
# ------------------------------------------------------------------------------
# You have a hash that represents all of Facebook (lookit you).  Each key is the
# name of a person on facebook, and each value is an array of all their friends.
# Assume everyone on Facebook has a different name.
#
# Given Facebook and the name of a person, return an array of all the friends
# of their friends. Do not include the original person or their immediate friends.
Two Degrees of Separation
You have a hash that represents all of Facebook (lookit you).  Each key is the
name of a person on facebook, and each value is an array of all their friends.
Assume everyone on Facebook has a different name.

Given Facebook and the name of a person, return an array of all the friends
of their friends. Do not include the original person or their immediate friends.
Two Degrees of Separation You have a hash that represents all of Facebook ( lookit you ) . Each key is the name of a person on facebook and each value is an array of all their friends . Assume everyone on Facebook has a different name . Given Facebook and the name of a person return an array of all the friends of their friends . Do not include the original person or their immediate friends .
def two_degrees_away(facebook, name)
  my_friends = facebook[name]
  my_friends << name
  their_friends = []
  my_friends.each do |my_friend|
    her_friends = facebook[my_friend]
    her_friends.each do |her_friend|
      if !my_friends.include?(her_friend)
        their_friends << her_friend
      end
    end
  end
  their_friends
end
def two_degrees_away ( facebook , name ) my_friends = facebook [ name ] my_friends << name their_friends = [ ] my_friends . each do | my_friend | her_friends = facebook [ my_friend ] her_friends . each do | her_friend | if ! my_friends . include? ( her_friend ) their_friends << her_friend end end end their_friends end
Two Degrees of Separation
You have a hash that represents all of Facebook (lookit you).
Two Degrees of Separation You have a hash that represents all of Facebook ( lookit you ) .
# facebook: key: name, value: array of friends # only friends of friends, NOT mutual friend # I'm also "my friend" # if my friends, friend is not a mutual connection
facebook
<not_specific>
name
<not_specific>