title: How to transform an array of promise objects into a promise object of an array?
body: <p>Is there a way to transform an array of promise objects into a promise object of an array? I'm looking for something that behaves kind of like <a href="http://docs.angularjs.org/api/ng.%24q" rel="nofollow"><code>$q.all(promises)</code></a> in AngularJS.</p>
  
  <p>Here's my code:  </p>
  
  <pre><code>var getPages = function(courses) {
    var courses_promises = courses.filter(function(item) {
      return item.courses[0].home_link;
    }).map(function(item) {
      deferred = $.Deferred();
      item["class_link"] = item.courses[0].home_link;
      item["home_link"] = item["class_link"] + "class/index";
      $.get(item.home_link)
         .then(function(response) {
          item["html"] = response;
          deferred.resolve(item);
         });
      return deferred.promise();
    });
    return $.when.apply($, courses_promises);
  };  
  </code></pre>
  
  <p>I want the <code>getPages</code> function to return a single promise that will be resolved with an array of values, each value corresponding to the promise at the same index in the promises array. If any of the promises is resolved with a rejection, this resulting promise will be resolved with the same rejection.</p>
  
  <p>And then I would use</p>
  
  <pre><code>getPages.then(getEvents)
  </code></pre>
  
  <p>where <code>getEvents</code> is another function which expects an array with the elements resolved by <code>getPages</code>.</p>
  
  <p>Can anyone help me out? Thank you!</p>