当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

equals

优质
小牛编辑
134浏览
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();
}
NameType(s)Description
otherSequence

The other sequence to compare this one to.

equalityFnFunction?

An optional equality function, which should take two arguments and return true or false to indicate whether those values are considered equal.

returnsboolean

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