jQuery object equality

Since jQuery 1.6, you can use .is. Below is the answer from over a year ago… var a = $(‘#foo’); var b = a; if (a.is(b)) { // the same object! } If you want to see if two variables are actually the same object, eg: var a = $(‘#foo’); var b = a; …then … Read more

Comparing two collections for equality irrespective of the order of items in them

It turns out Microsoft already has this covered in its testing framework: CollectionAssert.AreEquivalent Remarks Two collections are equivalent if they have the same elements in the same quantity, but in any order. Elements are equal if their values are equal, not if they refer to the same object. Using reflector, I modified the code behind … Read more

Elegant ways to support equivalence (“equality”) in Python classes

Consider this simple problem: class Number: def __init__(self, number): self.number = number n1 = Number(1) n2 = Number(1) n1 == n2 # False — oops So, Python by default uses the object identifiers for comparison operations: id(n1) # 140400634555856 id(n2) # 140400634555920 Overriding the __eq__ function seems to solve the problem: def __eq__(self, other): “””Overrides … Read more

What is the difference between the `=` and `==` operators and what is `===`? (Single, double, and triple equals)

= is the assignment operator. It sets a variable (the left-hand side) to a value (the right-hand side). The result is the value on the right-hand side. == is the comparison operator. It will only return true if both values are equivalent after coercing their types to the same type. === is a more strict … Read more