Needed polyfill.
[scpubgit/stemmaweb.git] / root / js / common.js
CommitLineData
cb397725 1//Array.find polyfill for browsers that don't support it
2
3if (!Array.prototype.find) {
4 Array.prototype.find = function(predicate) {
5 if (this == null) {
6 throw new TypeError('Array.prototype.find called on null or undefined');
7 }
8 if (typeof predicate !== 'function') {
9 throw new TypeError('predicate must be a function');
10 }
11 var list = Object(this);
12 var length = list.length >>> 0;
13 var thisArg = arguments[1];
14 var value;
15
16 for (var i = 0; i < length; i++) {
17 value = list[i];
18 if (predicate.call(thisArg, value, i, list)) {
19 return value;
20 }
21 }
22 return undefined;
23 };
24}