Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dz-3 beta #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions dz3_Khudyakov.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var events = [];
for (i = 1; i < 31; i++) {
events.push({
"name": "Событие №" + i, // тридцать событий
"start": "2012," + (Math.round(Math.random() * 11) + 1) + ",1,12,00,0", // различающихся месяцем
"location": Math.round(Math.random() * 2), // пусть будет три основных локации
"allDay": Math.round(Math.random()), // весь день
"stars": Math.round(Math.random() * 4) + 1, // случайный рейтинг
"withMe": Math.round(Math.random()) // с моим участием
});
};

var result = events.map(function(event) {
return event.name + ", начало: " + event.start + ", гео: " + event.location + ", весь день: " + event.allDay + ", рейтинг: " + event.stars + ", пойду: " + event.withMe + ".";
});
console.log(result.join("<br/>")); // вывод коллекции из 30 случайных событий

var allWithMe = events.filter(function(event) {
return event.withMe === 1;
});

console.log(allWithMe.length); // количество событий с моим участием

var allDayEvent = events.filter(function(event) {
return event.allDay === 1;
})
.map(function (event) {
return event.name;
})
.join(', ');

console.log(allDayEvent); // имена событий протяженностью весь день

var fiveStars = events.filter(function (event) {
return event.stars === 5;
})
.map(function (event) {
return event.name;
})
.join(', ');

console.log(fiveStars); // имена событий с пятью звёздами

var locationEvent = events.filter(function (event) {
return event.location === 0;
})
.map(function (event) {
return event.name;
})
.join(', ');

console.log(locationEvent); // имена событий, происходящих в первой ("нулевой") локации