title: Turn Array Into List With JavaScript
body: <p>I'm reading through <a href="http://eloquentjavascript.net/04_data.html" rel="nofollow noreferrer">Eloquent JavaScript</a> and at the end of Chapter 4 it challenges you to turn an array into a list i.e.</p>
  
  <p><code>[1, 3, 3] --&gt; {value: 1, rest: {value: 2, rest: {value: 3, rest: null}}};</code></p>
  
  <p>And I do not think I'm understanding the concept. </p>
  
  <p>It suggested iterating backward through the array, so I had tried: </p>
  
  <pre><code>function arrayToList(array) {
      let list = {};
      for (let i = array.length -1; i &gt; array[0]; i--) {
          list += ("value:" + i + ", rest: null");
      }
      return list;
  }
  
  console.log(arrayToList([1, 2, 3]));
  </code></pre>
  
  <p>And this logs out: </p>
  
  <p><code>[object Object]value:2, rest: null</code></p>
  
  <p>As you can see I'm not understanding how to create "nested" objects (lists) with iteration. Can someone please explain this to me?</p>