Assignment: Array equivalence
JavaScript has no standard way of comparing arrays for equivalence.
We cannot overload the === operator for arrays.
But we can provide a function eq such that for all arrays xs and ys
xs.eq(ys) is true if and only if for all valid indexes i the condition
xs[i] === ys[i] is true.
Provide the eq function. Only arrays of the same length can be equal.
You can ignore errors that arise from xs or ys not being of type array.
Solution
Array.prototype.eq = function (a) {
return this.length === a.length && this.every((e, i) => e === a[i]);
}Your solution will be tested against:
xs1_.eq(ys1_) && ! xs2_.eq(ys2_) && xs3_.eq(ys3_) && ! xs3_.eq(ys4_) && ! xs4_.eq(ys3_)