Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
(def b (identical? x y))
for external entities, identical will check if references point to the same object
(def b (= x y))
for clojure entities, = will always use deep equality
b = deeplyEqual(x, y));
See the online demo for more information about the function deeplyEqual (20 LOC).
b = x == y
the == operator will automatically deeply compare both values
b = x == y
Haskell always deeply compares values.
const b = JSON.stringify(x) === JSON.stringify(y);
Won't work for things which aren't serializable (such as functions) or recursive.
const arrayDeepEqual = (a, b) => a.length === b.length && a.every((x, i) => deepEqual(x, b[i]))
const deepEqual = (a, b) =>
Array.isArray(a) && Array.isArray(b)
? arrayDeepEqual(a, b)
: typeof a == 'object' && a && typeof b == 'object' && b
? arrayDeepEqual(Object.entries(a), Object.entries(b))
: Number.isNaN(a) && Number.isNaN(b) || a === b
const b = deepEqual(x, y)
This does not handle recursive types, Maps/Sets/Dates, the prototype/class of objects, or non-enumerable properties such as symbols.
const b = isDeepStrictEqual(x, y)
Only works in Node.js. This correctly handles recursive types.
Only enumerable own properties are considered, object wrappers are compared both as objects and unwrapped values, and WeakMap and WeakSet comparisons do not rely on their values.
Only enumerable own properties are considered, object wrappers are compared both as objects and unwrapped values, and WeakMap and WeakSet comparisons do not rely on their values.
$b = ($x == $y);
PHP's == behavior for objects does a deep comparison. This can lead to recursion issues, of course.
my $b = Compare($x, $y);
Old module with twenty years worth of patches, it probably works for absolutely everything by now
b = x == y
The classes of x and y need to delegate to any contained objects' _eq__ implementation.
All objects in the standard library do so.
All objects in the standard library do so.
b = x == y
x and y may contain themselves!
let b = x == y;
The == operator can only be used by having a type implement PartialEq.
case class A(a: Int, b: Float, c: String)
val x = A(1,2.2f,"hello")
val y = A(1,2.2f,"hello")
b = x == y
(define b (equal? x y))