Code coverage report for jsot-bh/flatten.js

Statements: 100% (12 / 12)      Branches: 100% (2 / 2)      Functions: 100% (1 / 1)      Lines: 100% (12 / 12)      Ignored: none     

All files » jsot-bh/ » flatten.js
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  1 18         18 37 37 7   7     7 7 11     30     18    
/* Lodash implementation of flatten */
module.exports = function flatten(array) {
    var index = -1,
        length = array.length,
        resIndex = 0,
        result = [];
 
    while (++index < length) {
        var value = array[index];
        if (Array.isArray(value)) {
            value = flatten(value);
 
            var valIndex = -1,
            valLength = value.length;
 
            result.length += valLength;
            while (++valIndex < valLength) {
                result[resIndex++] = value[valIndex];
            }
        } else {
            result[resIndex++] = value;
        }
    }
    return result;
};