title: JS array sort with regex
body: <p>My objective is to sort an array based on the priority of JS object that uses regular expressions. Here's what I have:</p>
  
  <p>JS objects defined:</p>
  
  <pre><code>var rx_CondoIndicator = new RegExp(/\bCONDO(MINIUM)?(?!S)/);
  
  var rx_TownhouseIndicator = new RegExp(/\bTOWN\s*(HOUSE|HOME)(?!S)/);
  
  var rx_TimeshareIndicator = new RegExp(/\bTIMESHARE(?!S)/);
  </code></pre>
  
  <p>Sort objects defined:</p>
  
  <pre><code>var so_UnitKeywordIndicator = {
      rx_CondoIndicator: 1,
      rx_TownhouseIndicator: 2,
      rx_TimeshareIndicator: 3
  };
  
  arrUnitNumber = ['TIMESHARE A-1', 'TOWNHOUSE 407', 'CONDO #13'] 
  </code></pre>
  
  <p>The following logic ignores the sort object priority and does not sequence the array in the desired order which is "CONDO #13", "TOWNHOUSE 407", "TIMESHARE A-1"</p>
  
  <pre><code>arrUnitNumber.sort(function(x,y){
      return so_UnitKeywordIndicator[x] - so_UnitKeywordIndicator[y];
  })
  </code></pre>
  
  <p>Please note that only a fraction of the JS sort objects are shown for brevity.</p>
  
  <p>If this is not the best solution for the problem, I'm open to any suggestions being a novice at JS.</p>