Array with promises

First up, the problem: I needed to build an array of items based on multiple roles for a user in an Angular application. And the returning value had to be a promise. So first attempt was to build up the array with if-statements and Array.push, not very beautiful nor immutable, and then return it with $q.when(array).

So I figured that this could be done with multiple promises instead. So here’s what I came up with, fun with trolls and ogres.

Pretty self explaining, ey?

Sometimes I see trolls when in the forest chopping firewood. Please come with an even more elegant way! 🙂