title: Snowflake Javascript to count between two element in a array
body: <p>I have an array with dates in ascending order, I am trying to create a Snowflake UDF to count the array element between two dates.</p>
  <p>The function should get the two days and tell us the count between the two days.</p>
  <pre><code>    create or replace function workdays_between(date1 String, date2 String)
   RETURNS double
    LANGUAGE JAVASCRIPT
    as 
    $$
    var DATE1 = DATE1
    var DATE2 = DATE2
    var count = 1
    var i = 1
    a = [&quot;2017-01-01&quot;,&quot;2017-01-02&quot;,&quot;2017-01-03&quot;,&quot;2017-01-06&quot;,&quot;2017-01-09&quot;,&quot;2017-01-10&quot;]
    if (DATE1 &lt; DATE2) {
      for (i=1;a[i]&lt;=DATE2;i++) {
          if (a[i] &gt;= DATE1) {
           count = count + 1;
           }
        }
    }
      else
      {
          for (i=1;a[i]&lt;=DATE1;i++) {
          if (a[i] &gt;= DATE2) {
           count = count + 1;
          }
          }
          count = count * -1;
    }
       return count;
    $$
  </code></pre>
  <p>But I am not getting the desired output, please help.</p>