Package Exports
- or
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (or) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Returns the element of an array when the callback returns true.
Purpose
This module provides a similar function as Array.prototype.filter
, but
it returns the element, not an array. And it stops looping as soon as it
finds a result.
Usage
var arr = ['item', 'other', 'finally'];
var item = or(arr, function(item) {
return item === 'other';
});
console.log(item); // "other"
// Real world example
var matchesSelector = or(['matchesSelector', 'mozMatchesSelector',
'webkitMatchesSelector', 'oMatchesSelector',
'msMatchesSelector'], function(shim) {
return shim in document.documentElement;
});
document.getElementById('some')[matchesSelector]('#some'); // true
API
The module returns a function accepting the following arguments:
array
: the array on which to iteratecallback
: the function being calledcontext
: the context on which to call the callback
Contributors
License
MIT License.