forked from locutusjs/locutus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompact.js
More file actions
32 lines (30 loc) · 973 Bytes
/
Copy pathcompact.js
File metadata and controls
32 lines (30 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function compact () {
// http://kevin.vanzonneveld.net
// + original by: Waldo Malqui Silva
// + tweaked by: Jack
// + input by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// * example 1: var1 = 'Kevin'; var2 = 'van'; var3 = 'Zonneveld';
// * example 1: compact('var1', 'var2', 'var3');
// * returns 1: {'var1': 'Kevin', 'var2': 'van', 'var3': 'Zonneveld'}
var matrix = {},
that = this;
var process = function (value) {
var i = 0,
l = value.length,
key_value = '';
for (i = 0; i < l; i++) {
key_value = value[i];
if (Object.prototype.toString.call(key_value) === '[object Array]') {
process(key_value);
} else {
if (typeof that.window[key_value] !== 'undefined') {
matrix[key_value] = that.window[key_value];
}
}
}
return true;
};
process(arguments);
return matrix;
}