We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parentfff8cf8 commit9482eb3Copy full SHA for 9482eb3
superArrayOfObjects.js
@@ -0,0 +1,42 @@
1
+// Example data
2
+constaob=
3
+[
4
+{framework:'React.JS',website:'Paypal'},
5
+{framework:'React.JS',website:'Tesla'},
6
+{framework:'Angular',website:'Google'},
7
+{framework:'Vue.JS',website:'Vue'},
8
+{framework:'JavaScript',website:'inblack67'},
9
+]
10
+constsuperAob=(data,victim)=>{
11
+
12
+constobj={};
13
14
+data.forEach((data)=>{
15
+if(data.hasOwnProperty(victim)){
16
+if(obj[data[victim]]){
17
+obj[data[victim]]++;
18
+}
19
+else{
20
+obj[data[victim]]=1;
21
22
23
+})
24
25
+letsuperArrayOfObjects=[];
26
27
+for(constkeyinobj){
28
+superArrayOfObjects=[...superArrayOfObjects,{victim:key,count:obj[key]}];
29
30
31
+returnsuperArrayOfObjects;
32
33
34
+console.log(superAob(aob,'framework'));
35
36
+// output:-
37
+// [
38
+// { victim: 'React.JS', count: 2 },
39
+// { victim: 'Angular', count: 1 },
40
+// { victim: 'Vue.JS', count: 1 },
41
+// { victim: 'JavaScript', count: 1 }
42
+// ]