Sha256: 93d3e333ad16f547d327b45df722b4687604747a483d48da735ffbbca20729be

Contents?: true

Size: 1.06 KB

Versions: 62

Compression:

Stored size: 1.06 KB

Contents

define(['../lang/isArray', './append'], function (isArray, append) {

    /*
     * Helper function to flatten to a destination array.
     * Used to remove the need to create intermediate arrays while flattening.
     */
    function flattenTo(arr, result, level) {
        if (level === 0) {
            append(result, arr);
            return result;
        }

        var value,
            i = -1,
            len = arr.length;
        while (++i < len) {
            value = arr[i];
            if (isArray(value)) {
                flattenTo(value, result, level - 1);
            } else {
                result.push(value);
            }
        }
        return result;
    }

    /**
     * Recursively flattens an array.
     * A new array containing all the elements is returned.
     * If level is specified, it will only flatten up to that level.
     */
    function flatten(arr, level) {
        if (arr == null) {
            return [];
        }

        level = level == null ? -1 : level;
        return flattenTo(arr, [], level);
    }

    return flatten;

});

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.6 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.5 node_modules/bower/node_modules/mout/src/array/flatten.js
trusty-festivity-extension-2.5.4 node_modules/bower/node_modules/mout/src/array/flatten.js