What do you want to save?
Add Code snippet
New code examples
-
Javascript 2021-09-20 14:01:04
groupby javascript by instances
let people = [ { name: 'Alice', age: 21 }, { name: 'Max', age: 20 }, { name: 'Jane', age: 20 } ]; function groupBy(objectArray, property) { return objectArray.reduce(function (acc, obj) { let key = obj[property] if (!acc[key]) { acc... Add solution -
Javascript 2021-09-19 03:38:02
reduce javascript
const sum = array.reduce((accumulator, element) => { return accumulator + element; }, 0); // An example that will loop through an array adding // each element to an accumulator and returning it // The 0 at the end initializes accumulator to start at ... Add solution -
Javascript 2021-09-13 12:46:02
syntax of reduce in js
const sum = array.reduce((accumulator, element) => { return accumulator + element; }, 0); // An example that will loop through an array adding // each element to an accumulator and returning it // The 0 at the end initializes accumulator to start at ... Add solution -
Javascript 2021-09-09 08:31:02
The value associated with each key will be an array consisting of all the elements that resulted in that return value when passed into the callback.
function groupBy(array, callback) { return array.reduce((acc,cur) => { let key = callback(cur) acc[key] = acc[key] || []; acc[key].push(cur) return acc; },{}) } const decimals = [1.3, 2.1, 2.4]; const floored = function(num) {... Add solution