-
Notifications
You must be signed in to change notification settings - Fork 0
/
attribute.js
98 lines (89 loc) · 2.1 KB
/
attribute.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Task A.1
*/
var Attribute = [{
identifier:"a",
qualifier:"b",
label:"c",
ownerIds:[3,4]
},{
identifier:"d",
qualifier:"e",
label:"f",
ownerIds:[1,2]
},{
identifier:"g",
qualifier:"h",
label:"i",
ownerIds:[5,6]
}];
var owners_array = [{ownerId:1, name: "ab"},
{ownerId:2, name: "cd"},
{ownerId:3, name: "ef"},
{ownerId:4, name: "gh"}];
/**
* @param {number[]} ownerIds
* @return {Attribute[]) attributes
*/
/**
* Task A.2
*/
var att_len = Attribute.length;
function filter(){
var attributes = [];
for (var i = 0; i <= att_len - 1; i++) {
attributes.push(Attribute[i].identifier);
attributes.push(Attribute[i].qualifier);
attributes.push(Attribute[i].label);
attributes.push(Attribute[i].ownerIds);
};
return attributes;
}
var list = filter();
console.log("Task A.2 ", list);
/**
* Task A.Bonus
*/
function filter_owner(owner_id){
var attributes = [];
var att_ownerIds_len;
for (var i = 0; i <= att_len - 1; i++) {
att_ownerIds_len = Attribute[i].ownerIds.length;
for(var j = 0; j <= att_ownerIds_len - 1; j++){
if(Attribute[i].ownerIds[j] == owner_id) {
attributes.push(Attribute[i].identifier);
attributes.push(Attribute[i].qualifier);
attributes.push(Attribute[i].label);
attributes.push(Attribute[i].ownerIds);
}
}
}
return attributes;
}
var owner_atts = filter_owner(1);
console.log("Task A.Bonus ", owner_atts);
/**
* Task A.Super Bonus
*/
function filter_owners(owner_ids){
var attributes = [];
var att_ownerIds_len;
var owners_len = owner_ids.length;
for (var i = 0; i <= att_len - 1; i++) {
att_ownerIds_len = Attribute[i].ownerIds.length;
for(var j = 0; j <= att_ownerIds_len - 1; j++){
for(var k = 0; k <= owners_len - 1; k++){
if(Attribute[i].ownerIds[j] == owner_ids[k]) {
attributes.push(Attribute[i].identifier);
attributes.push(Attribute[i].qualifier);
attributes.push(Attribute[i].label);
attributes.push(Attribute[i].ownerIds);
}
}
}
}
return attributes;
}
var owner_ids = [4,5];
var owners_atts = filter_owners(owner_ids);
console.log("Task A.Super Bonus ", owners_atts);