Lists all with all with recursion

http://angularjs.org/

by anup1986

HTML

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<div class="container" ng-controller="MyCtrl">
    <div class="row">
        <div class="col-md-12"> <pre>
                {{combined|json}}
            </pre>
        </div>
    </div>
</div>

CSS

body {
    margin-top: 50px;
}

JavaScript

var myApp = angular.module('myApp', []);
console.clear();
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function restriction(id, name, typeId) {
    this.id = id;
    this.name = name;
    this.typeId = typeId;
};

function MyCtrl($scope) {
    $scope.name = 'Superhero';

    var restrictions = [
    new restriction(3, 'Juniors', 1),
    new restriction(4, 'Seniors', 1),
    new restriction(7, 'Men', 2),
    new restriction(8, 'Women', 2),
    new restriction(9, '54kg - 62kg', 3),
    new restriction(10, '64kg - 70kg', 3)];

    function generateCategories(lists, fn) {
        var values = [];
        function process(listIndex) {
            var list = lists[listIndex];
            // no list? create the value
            if (!list) {
                fn(values);
                return;
            }
            for (var i = 0; i < list.length; i++) {
                values[listIndex] = list[i];
                process(listIndex + 1);
            }
        }
        process(0);
    };

    var categories = [];
    function combineNames(params) {
        var name = '';
        _.each(params, function(param){
            name += param.name + ' | ';
        });
        name = name.substr(0, name.length -3);
        return name;
    };
    var groups = _.values(_.groupBy(restrictions, function (x) {
        return x.typeId;
    }));
    
    generateCategories(groups, function(nameParts){
        categories.push(combineNames(nameParts));
    });
    
    $scope.combined = categories;
};