-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask2.js
53 lines (48 loc) · 1.22 KB
/
task2.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
console.log("MM/DD/YYYY");
var objectMas = [
{
date: "10/17/2013"
},
{
date: "10/15/2013"
},
{
date: "08/07/2002"
},
{
date: "07/05/2007"
},
{
date: "01/02/2003"
},
{
date: "12/01/2003"
}
];
console.log("Початковий масив:");
for (var i = 0; i < objectMas.length; i++) {
console.log(objectMas[i].date);
}
//Сортування
var objectMasSort = objectMas.slice("");
objectMasSort.sort(function (a, b) {
return new Date(b.date) - new Date(a.date);
});
objectMasSort.reverse();
console.log("Відсортований масив:");
for (var i = 0; i < objectMasSort.length; i++) {
console.log(objectMasSort[i].date);
}
//Діапазон
var objectMasRange = [];
var startDate = new Date("12/01/2002");
var endDate = new Date("12/01/2008");
for (var i in objectMasSort) {
if (new Date(objectMasSort[i].date) > startDate && new Date(objectMasSort[i].date) < endDate) {
objectMasRange.push(objectMasSort[i]);
}
}
console.log("Масив з діапазону:");
for (var i = 0; i < objectMasRange.length; i++) {
console.log(objectMasRange[i].date);
}