Skip to content Skip to sidebar Skip to footer

Are There Any Higher Order Function To Return An Object From An Array Of Objects In Javascript?

LIVE CODE EXAMPLE: Background: Trying to learn javascript's higher order function, some redux theory and applying it through a data transformations example and have been failing fo

Solution 1:

Use Array.prototype.every:

function wrap(approvals) {
  return {
    type: approvals.every(a => a.dateApproved != null) ? 'APPROVED' : 'PENDING',
    approvals: approvals
  };
}

wrap(approved1);
// => Object {type: "APPROVED", approvals: Array[2]}

wrap(approved2);
// => Object {type: "PENDING", approvals: Array[2]}

Post a Comment for "Are There Any Higher Order Function To Return An Object From An Array Of Objects In Javascript?"