Are there any higher order function to return an object from an array of objects in javascript?
<h2><strong><a href="https://repl.it/EBT3/3" rel="nofollow">LIVE CODE EXAMPLE:</a></strong></h2>

<p><strong>Background:</strong></p>

<p>Trying to learn javascript's higher order function, some redux theory and applying it through a data transformations example and have been failing for the last few hours. :(</p>

<p><strong>Question:</strong></p>

<p>How can I iterate over the <code>approved1</code> or <code>approved2</code> and return a new object bases on <strong>2 cases</strong>. Furthermore, is there a way to do this with a higher order function like <code>Array.reduce()</code> or a combination baked in higher order functions? <strong>Lastly</strong>, if the final Object is wrapped in an array thats fine too.</p>

<p>I want this for a few reasons:</p>

<ul>
<li>immutability.</li>
<li>ease of testing.</li>
<li>learning purposes.</li>
</ul>

<p><strong>The 2 cases:</strong></p>

<ul>
<li><p>If <strong>all</strong> <code>dateApproved</code> values are <code>!== null</code> (in this example: <code>approval1</code> array) then return a new Object <em>(or Array wrapped Object)</em> which looks like:</p>

<p><code>{type: 'APPROVED', approvals: [...approved1]}</code></p></li>
<li><p>If <strong>any</strong> of the <code>dateApproved</code> values are equal to <code>null</code> (in this example: <code>approval2</code> array) return a new Object  <em>(or Array wrapped Object)</em> which looks like: </p>

<p><code>{type: 'PENDING', approvals: [...approved2]}</code></p></li>
</ul>

<hr>

<p><strong>JAVASCRIPT:</strong></p>

<pre><code>// With given logic this array evaluate with a type of 'APPROVED'
var approved1 = [

    {
        dateApproved: new Date(),
        id: 1,
    },
    {
        dateApproved: new Date(),
        id: 2,
    }
];

// With given logic this array evaluate with a type of 'PENDING'
var approved2 = [

    {
        dateApproved: null,
        id: 1,
    },
    {
        dateApproved: new Date(),
        id: 2,
    }
];

// This reducer does nothing proper right now just placeholder.
function isApproved(previousValue, currentValue, currentIdx) {
    var TYPE = ['APPROVED', 'PENDING'];
    if(previousValue.dateApproved !== null &amp;&amp; currentValue.dateApproved !== null) {

      return currentValue
    }
}

var x = approved1.reduce(isApproved);
console.log(x); // LOG: {type: 'APPROVED' approvals: [...approved1]}

var y = approved2.reduce(isApproved);
console.log(x); // LOG: {type: 'PENDING' approvals: [...approved2]}
</code></pre>