Last active
September 21, 2016 18:35
-
-
Save theotherzach/8f077ca97a726d602a553ac253dee821 to your computer and use it in GitHub Desktop.
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
a = [{ slug: "foo"}, { slug: "bar" }] | |
b = a.sort_by { |e| e[:slug] } | |
a.push({ slug: "baz" }) | |
result_1 = b.find { |e| e[:slug] == "baz" } | |
# Predict which branch executes | |
if (result_1.nil?) | |
p "Elements pushed into array a DO NOT appear in array b" | |
else | |
p "Elements pushed into array a DO appear in array b" | |
end | |
foo = b.find { |e| e[:slug] == "foo" } | |
foo[:marked] = true | |
result_2 = a.find { |e| e[:marked] } | |
# Predict which branch executes | |
if (result_2.nil?) | |
p "Mutating one array's elements HAS NO effect on the other's" | |
else | |
p "Mutating one array's elements CAN HAVE an effect on the other" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment