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