source: frontend/node_modules/underscore/amd/_flatten.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1016 bytes
Line 
1define(['./_getLength', './_isArrayLike', './isArray', './isArguments'], function (_getLength, _isArrayLike, isArray, isArguments) {
2
3 // Internal implementation of a recursive `flatten` function.
4 function flatten(input, depth, strict, output) {
5 output = output || [];
6 if (!depth && depth !== 0) {
7 depth = Infinity;
8 } else if (depth <= 0) {
9 return output.concat(input);
10 }
11 var idx = output.length;
12 for (var i = 0, length = _getLength(input); i < length; i++) {
13 var value = input[i];
14 if (_isArrayLike(value) && (isArray(value) || isArguments(value))) {
15 // Flatten current level of array or arguments object.
16 if (depth > 1) {
17 flatten(value, depth - 1, strict, output);
18 idx = output.length;
19 } else {
20 var j = 0, len = value.length;
21 while (j < len) output[idx++] = value[j++];
22 }
23 } else if (!strict) {
24 output[idx++] = value;
25 }
26 }
27 return output;
28 }
29
30 return flatten;
31
32});
Note: See TracBrowser for help on using the repository browser.