-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
186 lines (138 loc) · 3.82 KB
/
test.js
File metadata and controls
186 lines (138 loc) · 3.82 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Lets assume I have arrays of Strings ( but it should work aslo with array of numbers).
//
// I would like to create a Map object over them with one of the 2 as key, but basically to establish a
// relationship. After that next step would be create a Map from 2 Array of Objects, but this is a bit
// more complicated
// unfortunately my approch somehow is missing something as
// Deck of Cards
// var suits = [
// {suit: "clubs",color: "black"},
// {suit: "spades",color: "black"},
// {suit: "hearts",color: "red"},
// {suit: "diamonds",color: "red"}
// ];
// var family = [
// {name: "2",value: 2},
// {name: "3",value: 3},
// {name: "4",value: 4},
// {name: "5",value: 5},
// {name: "6",value: 6},
// {name: "7",value: 7},
// {name: "8",value: 8},
// {name: "9",value: 9},
// {name: "10",value: 10},
// {name: "J",value: 10},
// {name: "Q",value: 10},
// {name: "K",value: 10},
// {name: "A",value: 1},
// ];
var arr = ['apple','cat','Adam','123','Zorro','petunia'];
var n = arr.length;
var tempArr = [];
for ( var i = 0; i < n-1; i++ ) {
// The following line removes one random element from arr
// and pushes it onto tempArr
tempArr.push(arr.splice(Math.floor(Math.random()*arr.length),1)[0]);
}
// Push the remaining item onto tempArr
tempArr.push(arr[0]);
arr=tempArr;
let products = [
{
name: "chair",
inventory: 5,
unit_price: 45.99,
client:'MG Gmbh'
},
{
name: "table",
inventory: 10,
unit_price: 123.75,
client : "XYZ"
},
{
name: "sofa",
inventory: 2,
unit_price: 399.50,
client : "MongoDB"
}
];
let clients =[
{
name:"MG Gmbh",
address: 'Linen street',
country: 'Germany'
},
{
name:'XYZ',
address:'Mongomery street',
country: 'USA'
},
{
name:'MongoDB',
address: 'NoSQL road',
country: 'UK'
},
{
name:'Zeppelin',
address: 'lienestraße',
country: 'Germany'
}
]
let engWords = ['house','gift','zoo','tidy','flat','to play',' to see','boy','ice cream']
// let numbers = [1,'gift','zoo','tidy','flat','to play',' to see','boy','ice cream']
let itaWords = ['casa','regalo','zoo','ordinato','appartamento','giocare','guardare','ragazzo','gelato']
let pairsMap = new Map();
let productsMap = new Map();
// var people = [
// { name: 'Alice', age: 21 },
// { name: 'Max', age: 20 },
// { name: 'Jane', age: 20 }
// ];
// var groupedPeople = groupBy(people, 'age');
// keys.forEach((key, i) => result[key] = values[i]);
for( val in engWords){
const nk = engWords[val];
engWords.forEach(function(element) {
pairsMap.set(nk,itaWords[val]);
} )
}
for (let [b, z] of pairsMap){
console.log(b, " -> ", z)
}
function groupBy(objectArray, property) {
return objectArray.reduce(function (acc, obj) {
var key = obj[property];
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(obj);
return acc;
}, {});
}
let groupedClients = groupBy(clients, 'name');
let clients_name = console.log(groupedClients);
for( val in clients){
const nk = clients[val];
products.forEach(function(element) {
productsMap.set(nk,products[val]);
} )
}
for (let [b, z] of productsMap){
console.log(b, " -> ", z)
}
// for( val in suits){
// const nk = suits[val];
// itaWords.forEach(function(element) {
// pairsMap.set(nk,family[val]);
// } )
// }
// var deck = new Array();
// suits.forEach(function(x){
// var arr = family.map( (y) => {
// var obj = Object.assign({}, x, y);
// deck.push(obj);
// return obj;
// });
// });
// console.log(deck);