some
优质
小牛编辑
135浏览
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; }
Name | Type(s) | Description |
---|---|---|
predicate | Function? | A function to call on (potentially) every element in this sequence. |
returns | boolean | True if |
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