equals
优质
小牛编辑
149浏览
2023-12-01
Compare this to another sequence for equality.
Signature
Sequence.equals = function(other, equalityFn) { /*...*/ }
Sequence.equals = function equals(other, equalityFn) {
if (!(other instanceof Sequence)) {
return false;
}
var it = this.getIterator(),
oit = other.getIterator(),
eq = equalityFn || Lazy.equality;
while (it.moveNext()) {
if (!oit.moveNext()) {
return false;
}
if (!eq(it.current(), oit.current())) {
return false;
}
}
return !oit.moveNext();
}
Name | Type(s) | Description |
---|---|---|
other | Sequence | The other sequence to compare this one to. |
equalityFn | Function? | An optional equality function, which should take two arguments and return true or false to indicate whether those values are considered equal. |
returns | boolean | Whether the two sequences contain the same values in the same order. |
Examples
Lazy([1, 2]).equals(Lazy([1, 2])) // => true
Lazy([1, 2]).equals(Lazy([2, 1])) // => false
Lazy([1]).equals(Lazy([1, 2])) // => false
Lazy([1, 2]).equals(Lazy([1])) // => false
Lazy([]).equals(Lazy([])) // => true
Lazy(['foo']).equals(Lazy(['foo'])) // => true
Lazy(['1']).equals(Lazy([1])) // => false
Lazy([false]).equals(Lazy([0])) // => false
Lazy([1, 2]).equals([1, 2]) // => false
Lazy([1, 2]).equals('[1, 2]') // => false