title: Get last 2 elements of an array in a selector (Redux)
body: <p>An array starts as [] and then keeps growing with numbers being added to it.</p>
  
  <p>I'm trying to create a selector to extract the last 2 elements of the array.</p>
  
  <p>I've got the following:</p>
  
  <pre><code>const getHistory = (state) =&gt; state.score.history;
  
  export const lastTwo = createSelector(
    [getHistory],
    history =&gt; (history.length &gt; 1 ? history.slice(-1, -3) : 0)
  );
  </code></pre>
  
  <p>It shows the initial 0 but then it does not output any value. Please advise. If, just for testing purposes, I do:</p>
  
  <pre><code>export const lastTwo = createSelector(
        [getHistory],
        history =&gt; history
      );
  </code></pre>
  
  <p>It outputs the array elements correctly as they are being added.</p>
  
  <p>EDIT:</p>
  
  <p>Based on the answer below, the answer is:</p>
  
  <pre><code>export const lastTwo = createSelector(
            [getHistory],
            history =&gt; history.slice(-2)
          );
  </code></pre>