js container class

Solutions on MaxInterview for js container class by the best coders in the world

showing results for - "js container class"
Ida
09 Jun 2018
1function Branches() {
2
3    function Branch() {
4        var _id;
5
6        _id = Math.round(Math.random()*10);
7
8        this.getId = function() {
9            return _id;
10        }
11
12    }
13
14    this.createBranch = function() {
15        var branch = new Branch;
16        _branches.push(branch);
17    }
18
19    this.getBranches = function() {
20        return _branches;
21    }
22
23    this.getBranchIds = function() {
24        var branch_list = this.getBranches();
25
26        var branch_ids = [];
27
28        for (var i = 0; i < branch_list.length; i++) {
29            var branch_id = branch_list[i].getId();
30            branch_ids.push(branch_id);
31        }
32
33        return branch_ids;
34    }
35
36    var _branches = [];
37
38}
39
40// code test
41var test = new Branches;
42
43for (var i = 0; i < 7; i++) {
44    test.createBranch();
45}
46
47console.log("Branch IDs:\n" + test.getBranchIds());
48