Check whether one binary tree is the mirror image of another
A layout engine supports right-to-left languages by mirroring its component tree: every container’s children appear in the opposite order. To check that the mirroring step is correct, the test suite compares the original tree with the mirrored one.
Implement isMirror(a, b). It returns true if binary tree b is the mirror image of binary tree a, and false otherwise.
isMirror(a, b) // => boolean
{ value, left, right }. left and right are child nodes, or null, or missing (undefined). All three mean “no child”. Any other properties are ignored.a and b are root nodes, or null for an empty tree.value can be anything, including falsy values such as 0, '' and null.b is the mirror of a when:
===), b.right is the mirror of a.left, and b.left is the mirror of a.right.An empty tree is never the mirror of a non-empty one. A tree is the mirror of itself only when it is symmetric.
// 1 1
// / \ / \
// 2 3 3 2
// / \
// 4 4
isMirror(a, b); // => true
// 1 1
// / /
// 2 2
isMirror(c, d); // => false (d would need 2 on the right)
isMirror(null, null); // => true
isMirror({ value: 1 }, null); // => false
isMirror({ value: 1 }, { value: '1' }); // => false (strict equality)