Needed polyfill.
[scpubgit/stemmaweb.git] / root / js / common.js
diff --git a/root/js/common.js b/root/js/common.js
new file mode 100644 (file)
index 0000000..7c38cd6
--- /dev/null
@@ -0,0 +1,24 @@
+//Array.find polyfill for browsers that don't support it
+
+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;
+  };
+}