title: JavaScript : Sorting an array
body: <p><strong>Unsorted array [input] :</strong></p>
  
  <pre><code>["&gt; 30 days", "&lt; 7 days", "&lt; 30 days", "&lt; 10 days"];
  </code></pre>
  
  <p>The format of an elements in array will always be like : <code>&lt;/&gt; X days</code></p>
  
  <p><strong>Requirement :</strong></p>
  
  <p>Above mentioned array should be sorted as per the <strong><code>greater then (&gt;)</code></strong> and <strong><code>lesser then symbol (&lt;)</code></strong> and also keep the number of days in mind (less number of days should come first).</p>
  
  <p><strong>Expected Array [output] :</strong></p>
  
  <pre><code>["&lt; 7 days", "&lt; 10 days", "&lt; 30 days", "&gt; 30 days"];
  </code></pre>
  
  <p><strong>Tried so far :</strong></p>
  
  <p>I tried <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/sort" rel="nofollow noreferrer"><strong>Array.sort()</strong></a> function but did not get expected output.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var arr = ["&gt; 30 days", "&lt; 7 days", "&lt; 30 days", "&lt; 10 days"];
  
  var sortedArr = arr.sort();
  
  console.log(sortedArr); // ["&lt; 30 days", "&lt; 10 days", "&lt; 7 days", "&gt; 30 days"]</code></pre>
  </div>
  </div>
  </p>