← Back to challenges

Anti Array

JavaScriptHardarraysloopsvalidation

Instructions

Given two arrays, return whether the two arrays are opposites of each other. That means both arrays are comprised only from elements a and b and the occurrences of these elements are swapped between the two arrays.

Examples

isAntiArray(["1", "0", "0", "1"], ["0", "1", "1", "0"]) ➞ true

isAntiArray(["apples", "bananas", "bananas"], ["bananas", "apples", "apples"]) ➞ true

isAntiArray([3.14, True, 3.14], [3.14, False, 3.14]) ➞ false

Notes

All tests will include only two different elements.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.