Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[JavaScript] groupBy

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy

const people = [
  { name: "Max", age: 10 },
  { name: "Tim", age: 15 },
  { name: "Pip", age: 25 },
]

function adultsOnly({age}) {
if (age >= 18) {
    return 'adult'
  } else {
    return 'minor'
  }
} 

const organized = Object.groupBy(people, adultsOnly)

console.log(organized)

Leave a Reply

Your email address will not be published. Required fields are marked *