title: Shortest way to get unique sequence in array
body: <p>I have a JavaScript code that generates a pattern based on an array.</p>
  
  <p>Array below:</p>
  
  <pre><code>[1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]
  </code></pre>
  
  <p>will return:</p>
  
  <pre><code>[1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1]
  </code></pre>
  
  <p>However, I want the pattern to be simplified and only get the unique sequence which is:</p>
  
  <pre><code>[1, 1, 1, 1, -1, -1, -1, -1]
  </code></pre>
  
  <p>Is there any way I can achieve this with <code>slice()</code> or <code>filter()</code>?
  If not, then any suggestions on how I can?</p>
  
  <p>Please do take note that the array pattern and the unique sequence will be variable in length.</p>