summaryrefslogtreecommitdiffstats
path: root/js/dav/lib/polyfill/array_find.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/dav/lib/polyfill/array_find.js')
-rw-r--r--js/dav/lib/polyfill/array_find.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/js/dav/lib/polyfill/array_find.js b/js/dav/lib/polyfill/array_find.js
new file mode 100644
index 00000000..e07b3743
--- /dev/null
+++ b/js/dav/lib/polyfill/array_find.js
@@ -0,0 +1,25 @@
+/**
+ * Polyfill from developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/find
+ */
+if (!Array.prototype.find) {
+ Array.prototype.find = function(predicate) {
+ if (this == null) {
+ throw new TypeError('Array.prototype.find called on null or undefined');
+ }
+ if (typeof predicate !== 'function') {
+ throw new TypeError('predicate must be a function');
+ }
+ var list = Object(this);
+ var length = list.length >>> 0;
+ var thisArg = arguments[1];
+ var value;
+
+ for (var i = 0; i < length; i++) {
+ value = list[i];
+ if (predicate.call(thisArg, value, i, list)) {
+ return value;
+ }
+ }
+ return undefined;
+ };
+}