summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/extensions/array.js
diff options
context:
space:
mode:
authorLuke "Jared" Bennett <lbennett@gitlab.com>2017-02-07 18:02:49 +0000
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-02-07 18:33:00 +0000
commitdf469864b1ab1e0bfaa1e843d3d0a84042604646 (patch)
tree81a59a012180c8e2c43f8573a50d5ddec26040ab /app/assets/javascripts/extensions/array.js
parentbc13687c7e374116e4830d004b82e9960d3a55cc (diff)
downloadgitlab-ce-update-filenames-regex.tar.gz
Updated the filename regexupdate-filenames-regex
Diffstat (limited to 'app/assets/javascripts/extensions/array.js')
-rw-r--r--app/assets/javascripts/extensions/array.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/assets/javascripts/extensions/array.js b/app/assets/javascripts/extensions/array.js
new file mode 100644
index 00000000000..f8256a8d26d
--- /dev/null
+++ b/app/assets/javascripts/extensions/array.js
@@ -0,0 +1,27 @@
+/* eslint-disable no-extend-native, func-names, space-before-function-paren, space-infix-ops, strict, max-len */
+
+'use strict';
+
+Array.prototype.first = function() {
+ return this[0];
+};
+
+Array.prototype.last = function() {
+ return this[this.length-1];
+};
+
+Array.prototype.find = Array.prototype.find || function(predicate, ...args) {
+ if (!this) throw new TypeError('Array.prototype.find called on null or undefined');
+ if (typeof predicate !== 'function') throw new TypeError('predicate must be a function');
+
+ const list = Object(this);
+ const thisArg = args[1];
+ let value = {};
+
+ for (let i = 0; i < list.length; i += 1) {
+ value = list[i];
+ if (predicate.call(thisArg, value, i, list)) return value;
+ }
+
+ return undefined;
+};