forked from vijayasagarMantapudi/begin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
97 lines (90 loc) · 2.01 KB
/
javascript.js
File metadata and controls
97 lines (90 loc) · 2.01 KB
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
var Person = {
firstName : "Srinayan Reddy",
lastName : "Gujjula",
age : "21"
}
class ParserClass{
#version;
#channel;
#keyField;
constructor(){
this.#version = "";
this.#channel = "";
this.#keyField = "";
};
setVersion(version) {
this.#version = version;
return this;
};
getVersion() {
return this.#version;
};
setChannel(channel) {
this.#channel = channel;
return this;
};
getChannel() {
return this.#channel;
};
setkeyField(keyField) {
this.#keyField = keyField;
return this;
};
getkeyField() {
return this.#keyField;
};
getKeyFields (jsonArray) {
var keyFieldsList = []
for (x in jsonArray) {
keyFieldsList.push(x.getKeyField());
}
return keyFieldsList;
};
}
function groupObjectsBy(jsonArray, key) {
return jsonArray.reduce(function (groups, item) {
console.log(groups,item);
const val = item[key]
groups[val] = groups[val] || []
groups[val].push(item)
return groups
}, {});
};
class SortArray{
#sortedArray;
constructor(... args){
this.originalArray = args
this.#sortedArray = []
}
#sort=function(){
this.#sortedArray = this.originalArray.sort();
}
getSortedArray(){
this.#sort();
return this.#sortedArray;
}
}
class SortObjectArray extends SortArray{
#sortedArray;
constructor(... args){
super(args);
}
#getSortOrder = function(key){
return function(a,b){
if (a[key]>b[key]){
return 1;
}
else if(a[key]<b[key]){
return -1;
}
return 0;
}
}
#sort = function (key) {
this.#sortedArray = this.originalArray[0].sort(this.#getSortOrder(key));
}
getSortedArray(key){
this.#sort(key);
return this.#sortedArray;
}
}