JavaScript How to group by an array and determine total count of rows using javascript

You could simplify the function for grouping and take that result for filtering to get same grouped objects in an array and then filter this for getting only the result sets with a length of one. If necessary take the obejects out of the array.

function groupBy(array, key) {
    return array.reduce((accumulator, object) => {
        var temp = accumulator.find(array => array[0][key] === object[key]);
        if (temp) {
            temp.push(object);
        } else {
            accumulator.push([object])
        }
        return accumulator;
    }, []);
}

var array = [{ bID: 1 }, { bID: 1 }, { bID: 2 }, { bID: 1 }, { bID: 3 }, { bID: 3 }, { bID: 4 }],
    result = groupBy(array, 'bID')
        .filter(({ length }) => length === 1)
        .map(([v]) => v);
    
console.log(result);
Answer:1

Strangely enough the module loads perfectly in Firefox. In Chrome only sometimes the module loads up (when refreshing on and off) and seems to be the only browser where the following console error ...

Strangely enough the module loads perfectly in Firefox. In Chrome only sometimes the module loads up (when refreshing on and off) and seems to be the only browser where the following console error ...

  1. angularjs error injector modulerr
  2. angularjs error injector unpr
  3. angularjs error injector nomod
  4. angularjs error injector
  5. angularjs injector error unknown provider
  6. angularjs uncaught error injector modulerr
  7. angularjs ngmaterial injector error
  8. angularjs factory injector error
  9. angularjs bootstrap injector error
  10. error injector modulerr
  11. uncaught error $ injector modulerr http errors angularjs org 1.6 9 /$ injector modulerr

I am having trouble understanding some weird behavior in my code and I am wondering if anyone can tell me what I am doing wrong? I have a Boolean variable isWaiting and it is saved as false in ...

I am having trouble understanding some weird behavior in my code and I am wondering if anyone can tell me what I am doing wrong? I have a Boolean variable isWaiting and it is saved as false in ...

I am making an ajax call using jquery to a PHP script that sends back a json encoded string as an object. { "errors":{ "name":"Name is empty", "gender":"Gender is empty" }, "...

I am making an ajax call using jquery to a PHP script that sends back a json encoded string as an object. { "errors":{ "name":"Name is empty", "gender":"Gender is empty" }, "...

In Nuxt.js, I did this folder structure: ├── parent │   ├── child1.vue │   └── child2.vue ├── parent.vue In parent.vue, I have this: <template> <div> <h3>Parent ...

In Nuxt.js, I did this folder structure: ├── parent │   ├── child1.vue │   └── child2.vue ├── parent.vue In parent.vue, I have this: <template> <div> <h3>Parent ...