Code coverage report for src/groupBy.js

Statements: 100% (28 / 28)      Branches: 100% (12 / 12)      Functions: 100% (2 / 2)      Lines: 100% (15 / 15)      Ignored: 4 statements, 3 branches     

All files » src/ » groupBy.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 27 281 7 7 7   7 1   6     7 39   39 19   20     39     7        
function groupBy(xs, iteratee, thisArg) {
    let i = 0;
    let groups = {};
    let fn;
 
    if (typeof iteratee === 'string') {
        fn = x => x[iteratee];
    } else {
        fn = thisArg ? iteratee.bind(thisArg) : iteratee;
    }
 
    for (let x of xs) {
        let key = fn(x, i, xs);
 
        if (groups[key]) {
            groups[key].push(x);
        } else {
            groups[key] = [x];
        }
 
        i += 1;
    }
 
    return groups;
}
 
export default groupBy;