title: What is the best way to compare two lists in Javascript as you would do in Python?
body: <p>I'm quite new with JavaScript but familiar with python. In Python I get this output:</p>
  
  <pre><code>In [1]: [1,9,[5,4,2]] &gt; [1,9,[14,5,4]]
  Out[1]: False
  </code></pre>
  
  <p>In JavaScript:</p>
  
  <pre><code>&gt; [1,9,[5,4,2]] &gt; [1,9,[14,5,4]]
  true
  </code></pre>
  
  <p>It seems that the arrays are converted into a string before the comparison.</p>
  
  <p>Now i wanted to write a function by myself and walk through the array an compare each element.
  I came up with this coffeescript code:</p>
  
  <pre><code>compare_list = (a, b)-&gt;
      if typeof a == "object" and typeof b != "object"
          return 1
      else if typeof a != "object" and typeof b == "object"
          return -1
      else if typeof a != "object" and typeof b != "object"
          if a &gt; b
              return 1
          else if a &lt; b
              return -1
          else
              return 0
      else if typeof a == "object" and typeof b == "object"
          for i in [0...a.length]
              if i &gt; (b.length-1)
                  return 1
              tmp = compare_list a[i], b[i]
              if tmp != 0
                  return tmp
          if b.length &gt; a.length
              return -1
          return 0
  </code></pre>
  
  <p>It works this way but the <code>typeof a == "object"</code> part looks not correct to me. Is there a simpler/better/more robust solution?</p>
  
  <p>Thanks for your help.</p>