summaryrefslogtreecommitdiff
path: root/node_modules/locutus/php/array/array_combine.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/locutus/php/array/array_combine.js')
-rw-r--r--node_modules/locutus/php/array/array_combine.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/node_modules/locutus/php/array/array_combine.js b/node_modules/locutus/php/array/array_combine.js
new file mode 100644
index 0000000..124f5fa
--- /dev/null
+++ b/node_modules/locutus/php/array/array_combine.js
@@ -0,0 +1,46 @@
+'use strict';
+
+var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
+
+module.exports = function array_combine(keys, values) {
+ // eslint-disable-line camelcase
+ // discuss at: http://locutus.io/php/array_combine/
+ // original by: Kevin van Zonneveld (http://kvz.io)
+ // improved by: Brett Zamir (http://brett-zamir.me)
+ // example 1: array_combine([0,1,2], ['kevin','van','zonneveld'])
+ // returns 1: {0: 'kevin', 1: 'van', 2: 'zonneveld'}
+
+ var newArray = {};
+ var i = 0;
+
+ // input sanitation
+ // Only accept arrays or array-like objects
+ // Require arrays to have a count
+ if ((typeof keys === 'undefined' ? 'undefined' : _typeof(keys)) !== 'object') {
+ return false;
+ }
+ if ((typeof values === 'undefined' ? 'undefined' : _typeof(values)) !== 'object') {
+ return false;
+ }
+ if (typeof keys.length !== 'number') {
+ return false;
+ }
+ if (typeof values.length !== 'number') {
+ return false;
+ }
+ if (!keys.length) {
+ return false;
+ }
+
+ // number of elements does not match
+ if (keys.length !== values.length) {
+ return false;
+ }
+
+ for (i = 0; i < keys.length; i++) {
+ newArray[keys[i]] = values[i];
+ }
+
+ return newArray;
+};
+//# sourceMappingURL=array_combine.js.map \ No newline at end of file