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

some

优质
小牛编辑
140浏览
2023-12-01

Checks whether at least one element in this sequence satisfies a given predicate (or, if no predicate is specified, whether the sequence contains at least one element).

Signature

Sequence.some = function(predicate) { /*...*/ }
Sequence.some = function some(predicate) {
  predicate = createCallback(predicate, true);

  var success = false;
  this.each(function(e) {
if (predicate(e)) {
  success = true;
  return false;
}
  });
  return success;
}
NameType(s)Description
predicateFunction?

A function to call on (potentially) every element in this sequence.

returnsboolean

True if predicate returns true for at least one element in the sequence. False if predicate returns false for every element (or the sequence is empty).

Examples

var numbers = [1, 2, 3, 4, 5];

Lazy(numbers).some()           // => true
Lazy(numbers).some(isEven)     // => true
Lazy(numbers).some(isNegative) // => false
Lazy([]).some()                // => false