-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendsrid.js
66 lines (55 loc) · 1.35 KB
/
sendsrid.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
function containsObject(obj, list) {
let count = 0;
let i;
let isExist = false;
for (i = 0; i < list.length; i++) {
if (list[i].lat === obj.lat && list[i].log === obj.log) {
count ++;
isExist = true
}
}
return {isExist, count};
}
function compare(a, b) {
// Use toUpperCase() to ignore character casing
const latA = a.lat;
const latB = b.lat;
let comparison = 0;
if (latA > latB) {
comparison = 1;
} else if (latA < latB) {
comparison = -1;
}
return comparison;
}
const arr = [
{ lat: 12.98, log: 13.67, x: 3.4 },
{ lat: 12.38, log: 13.27, x: 3.1 },
{ lat: 12.38, log: 13.27, x: 3.1 },
{ lat: 12.38, log: 13.27, x: 3.1 },
];
let newArray = [];
for(let i = 0; i < arr.length; i++) {
const result = newArray.length ? containsObject(arr[i], newArray) : newArray.push(arr[i]);
if(result.isExist) {
for(j = 0; j < result.count; j++) {
newArray.push(arr[i]);
}
i = i + result.count;
}
// else {
// newArray.splice(i,1);
// }
}
// for (let i = 0; i < arr.length; i++) {
// if (newArray.length && containsObject(arr[i], newArray).isExist) {
// continue;
// } else {
// for (let j = 0; j < arr.length; j++) {
// if (arr[i].lat === arr[j].lat && arr[i].log === arr[j].log) {
// newArray.push(arr[i]);
// }
// }
// }
// }
console.log(newArray);