-
Notifications
You must be signed in to change notification settings - Fork 10
Дз3 фильтрация. #3
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
Open
RooshRoosh
wants to merge
8
commits into
cripi-javascript:master
Choose a base branch
from
RooshRoosh:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
adf2e66
Загенерил случайные события. Начал писать выборку.
RooshRoosh 6489be6
Попробывал сортировать.
RooshRoosh b75098d
Теперь точно сортирует в ручном режиме.
RooshRoosh 5eb5344
Сортировка фильтрация
RooshRoosh f30e45e
Реализация простых запросов более/менее.
RooshRoosh 8b318e3
JSlint
RooshRoosh 7ffed32
Скрипты в отдельном файле
RooshRoosh 7280ab9
utf-8
RooshRoosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
//utf-8 | ||
var nameArray = ['Goga', 'Vasya', 'Petya', 'Zina', 'Ira', 'Masha', 'Dima', 'Tolya', 'Kolya', 'Marina', 'Gulya', 'Alyona', 'Zhenya', 'Ruslan', 'Uriy']; | ||
function Event(obj) { //Call, DateStart, DateFinish, Description, Parent, Childs, Comments, Peopleт, Location, Private, Rank, EvRS, Link | ||
'use strict'; | ||
return obj || {}; | ||
}; | ||
var lectureJS1 = {"start": new Date(2012, 9, 3, 19, 00, 00), | ||
"end": new Date(2012, 9, 3, 20, 00, 00), | ||
"name": "1 лекция по JavaScript", | ||
"description": "Обзор языка", | ||
"parent": {}, | ||
"childs": [lectureJS2, lectureJS3, lectureJS4], | ||
"comments": ['Красивенько', 'А мы могли бы...'], | ||
"people": nameArray, | ||
"location": {}, | ||
"private": true, | ||
"rank": 4, | ||
"EvRS": 16, | ||
"Link": 'http://cripi.ru/#javascript' | ||
}; | ||
var lectureJS2 = {"start":new Date(2012, 9, 10, 19, 00, 00), | ||
"end": new Date(2012, 9, 10, 21, 00, 00), | ||
"name": "2 лекция по JavaScript", | ||
"description": "Типы данных. Объекты. Statements. Expressions.", | ||
"parent": lectureJS1, | ||
"childs": [lectureJS3, lectureJS4], | ||
"comments": ['Можете вообще ничего не делать', 'Можно ли перенести на 19:30?'], | ||
"people": nameArray, | ||
"location": {}, | ||
"private": true, | ||
"rank": 4, | ||
"EvRS": 16, | ||
"Link": 'http://cripi.ru/#javascript' | ||
}; | ||
var lectureJS3 = {"start":new Date(2012, 9, 17, 19, 30, 00), | ||
"end": new Date(2012, 9, 17, 21, 00, 00), | ||
"name": "3 лекция по JavaScript", | ||
"description": "Итераторы и циклы", | ||
"parent": lectureJS2, | ||
"childs": [lectureJS4], | ||
"comments": ['Можете вообще ничего не делать', 'Можно ли перенести на 19:30?'], | ||
"people": nameArray, | ||
"location": {}, | ||
"private": true, | ||
"rank": 3, | ||
"EvRS": 16, | ||
"Link": 'http://cripi.ru/#javascript' | ||
}; | ||
var lectureJS4 = {"start":new Date(2012, 9, 24, 18, 30, 00), | ||
"end": new Date(2012, 9, 24, 21, 00, 00), | ||
"name": "4 лекция по JavaScript", | ||
"description": "ООП, которого нет", | ||
"parent": lectureJS3, | ||
"childs": [], | ||
"comments": [], | ||
"people": nameArray, | ||
"location": {}, | ||
"private": true, | ||
"rank": 0, | ||
"EvRS": 16, | ||
"Link": 'http://cripi.ru/#javascript' | ||
}; | ||
var eventArray = [lectureJS3, lectureJS4, lectureJS1, lectureJS2]; | ||
for (var nameIndex in nameArray) { | ||
var randomnumber = Math.random()*nameIndex; | ||
eventArray[eventArray.length]=(Event({ | ||
'people':[nameArray[nameIndex]], | ||
'name' : "Ещё одно событие"+nameIndex, | ||
'start' : new Date(2012, randomnumber, randomnumber*(1+Math.random()), 10+randomnumber*Math.random(), 00, 00), | ||
'end' : new Date(2012, randomnumber, randomnumber*2, 11+randomnumber, 30, 00), | ||
'rank' : (Math.random()*5).toFixed(0), | ||
'EvRS' : 16, | ||
})); | ||
}; | ||
//Закончили формировать случайные объекты. Переходим к выборке. | ||
function isData(data) { | ||
"use strict"; | ||
if (typeof data === 'undefined') {return false;} | ||
return data;} | ||
function Flt(A,varHash){ // filterFieldHash, sortedField, next, prew | ||
varHash = varHash || {}; | ||
curDate = isData(varHash['date']) || new Date(); | ||
next = isData(varHash['next']); | ||
prew = isData(varHash['prew']); | ||
filterField =isData(varHash['filterField']) || {}; | ||
sortedField = isData(varHash['sortedField']) || 'start'; | ||
if (next===true) { | ||
return A.filter(function (event){ //after - грядущие | ||
return event.start >= curDate; | ||
})}; | ||
if (prew==true){ | ||
return A.filter(function (event){ //pre - предыдущие | ||
return event.end < curDate; | ||
})}; | ||
|
||
//Проверка вхождения | ||
function inArray(looking_for, list){ | ||
for(i in list){ | ||
if(looking_for == list[i]){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
for (var field in filterField){ | ||
|
||
A = A.filter(function(event){ | ||
return inArray(filterField[field],event[field]); | ||
}); | ||
}; | ||
A.sort(function(a,b){ | ||
if (a[sortedField]>b[sortedField]){ | ||
return -1}; | ||
if (a[sortedField]<b[sortedField]) { | ||
return 1}; | ||
return 0; | ||
}); | ||
return A; | ||
}; | ||
|
||
console.log(['Прошедшие события',Flt(eventArray,{'next':true})]); | ||
console.log(['Событие с конкретным участником'],Flt(eventArray,{'filterField':{'people':'Ruslan'}})); | ||
console.log(['Предстоящие события',Flt(eventArray,{'prew':true})]); | ||
console.log(['События после определённой даты',Flt(eventArray,{'date':new Date(2012,5), 'next':true})]); | ||
console.log(['Все события отсортированные по возрастанию', Flt(eventArray)]); // Убывание доделать | ||
console.log(['Сортировка по рейтингу события',Flt(eventArray,{'sortedField':'rank'})]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset=utf-8> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
<p>Тестовый шаблон</p> | ||
<script> | ||
var nameArray = ['Goga', 'Vasya', 'Petya', 'Zina', 'Ira', 'Masha', 'Dima', 'Tolya', 'Kolya', 'Marina', 'Gulya', 'Alyona', 'Zhenya', 'Ruslan', 'Uriy']; | ||
function Event(obj) { //Call, DateStart, DateFinish, Description, Parent, Childs, Comments, Peopleт, Location, Private, Rank, EvRS, Link | ||
'use strict'; | ||
return obj || {}; | ||
}; | ||
var lectureJS1 = {"start": new Date(2012, 9, 3, 19, 00, 00), | ||
"end": new Date(2012, 9, 3, 20, 00, 00), | ||
"name": "1 лекция по JavaScript", | ||
"description": "Обзор языка", | ||
"parent": {}, | ||
"childs": [lectureJS2, lectureJS3, lectureJS4], | ||
"comments": ['Красивенько', 'А мы могли бы...'], | ||
"people": nameArray, | ||
"location": {}, | ||
"private": true, | ||
"rank": 4, | ||
"EvRS": 16, | ||
"Link": 'http://cripi.ru/#javascript' | ||
}; | ||
var lectureJS2 = {"start":new Date(2012, 9, 10, 19, 00, 00), | ||
"end": new Date(2012, 9, 10, 21, 00, 00), | ||
"name": "2 лекция по JavaScript", | ||
"description": "Типы данных. Объекты. Statements. Expressions.", | ||
"parent": lectureJS1, | ||
"childs": [lectureJS3, lectureJS4], | ||
"comments": ['Можете вообще ничего не делать', 'Можно ли перенести на 19:30?'], | ||
"people": nameArray, | ||
"location": {}, | ||
"private": true, | ||
"rank": 4, | ||
"EvRS": 16, | ||
"Link": 'http://cripi.ru/#javascript' | ||
}; | ||
var lectureJS3 = {"start":new Date(2012, 9, 17, 19, 30, 00), | ||
"end": new Date(2012, 9, 17, 21, 00, 00), | ||
"name": "3 лекция по JavaScript", | ||
"description": "Итераторы и циклы", | ||
"parent": lectureJS2, | ||
"childs": [lectureJS4], | ||
"comments": ['Можете вообще ничего не делать', 'Можно ли перенести на 19:30?'], | ||
"people": nameArray, | ||
"location": {}, | ||
"private": true, | ||
"rank": 3, | ||
"EvRS": 16, | ||
"Link": 'http://cripi.ru/#javascript' | ||
}; | ||
var lectureJS4 = {"start":new Date(2012, 9, 24, 18, 30, 00), | ||
"end": new Date(2012, 9, 24, 21, 00, 00), | ||
"name": "4 лекция по JavaScript", | ||
"description": "ООП, которого нет", | ||
"parent": lectureJS3, | ||
"childs": [], | ||
"comments": [], | ||
"people": nameArray, | ||
"location": {}, | ||
"private": true, | ||
"rank": 0, | ||
"EvRS": 16, | ||
"Link": 'http://cripi.ru/#javascript' | ||
}; | ||
var eventArray = [lectureJS3, lectureJS4, lectureJS1, lectureJS2]; | ||
for (var nameIndex in nameArray) { | ||
var randomnumber = Math.random()*nameIndex; | ||
eventArray[eventArray.length]=(Event({ | ||
'people':[nameArray[nameIndex]], | ||
'name' : "Ещё одно событие"+nameIndex, | ||
'start' : new Date(2012, randomnumber, randomnumber*(1+Math.random()), 10+randomnumber*Math.random(), 00, 00), | ||
'end' : new Date(2012, randomnumber, randomnumber*2, 11+randomnumber, 30, 00), | ||
'rank' : (Math.random()*5).toFixed(0), | ||
'EvRS' : 16, | ||
})); | ||
}; | ||
//Закончили формировать случайные объекты. Переходим к выборке. | ||
function isData(data) { | ||
"use strict"; | ||
if (typeof data === 'undefined') {return false;} | ||
return data;} | ||
function Flt(A,varHash){ // filterFieldHash, sortedField, next, prew | ||
varHash = varHash || {}; | ||
curDate = isData(varHash['date']) || new Date(); | ||
next = isData(varHash['next']); | ||
prew = isData(varHash['prew']); | ||
filterField =isData(varHash['filterField']) || {}; | ||
sortedField = isData(varHash['sortedField']) || 'start'; | ||
if (next===true) { | ||
return A.filter(function (event){ //after - грядущие | ||
return event.start >= curDate; | ||
})}; | ||
if (prew==true){ | ||
return A.filter(function (event){ //pre - предыдущие | ||
return event.end < curDate; | ||
})}; | ||
|
||
//Проверка вхождения | ||
function inArray(looking_for, list){ | ||
for(i in list){ | ||
if(looking_for == list[i]){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
for (var field in filterField){ | ||
|
||
A = A.filter(function(event){ | ||
return inArray(filterField[field],event[field]); | ||
}); | ||
}; | ||
A.sort(function(a,b){ | ||
if (a[sortedField]>b[sortedField]){ | ||
return -1}; | ||
if (a[sortedField]<b[sortedField]) { | ||
return 1}; | ||
return 0; | ||
}); | ||
return A; | ||
}; | ||
|
||
console.log(['Прошедшие события',Flt(eventArray,{'next':true})]); | ||
console.log(['Событие с конкретным участником'],Flt(eventArray,{'filterField':{'people':'Ruslan'}})); | ||
console.log(['Предстоящие события',Flt(eventArray,{'prew':true})]); | ||
console.log(['События после определённой даты',Flt(eventArray,{'date':new Date(2012,5), 'next':true})]); | ||
console.log(['Все события отсортированные по возрастанию', Flt(eventArray)]); // Убывание доделать | ||
console.log(['Сортировка по рейтингу события',Flt(eventArray,{'sortedField':'rank'})]); | ||
|
||
</script> | ||
|
||
|
||
|
||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вынеси скрипты в отдельнй файл