From 363ae6e9203c7779881c8fde1806237080fc9e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Thu, 24 Nov 2016 00:16:36 +0500 Subject: [PATCH 01/40] =?UTF-8?q?=D0=A0=D0=B5=D1=88=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/lib.js b/lib.js index 60f30ab..2bea05b 100644 --- a/lib.js +++ b/lib.js @@ -1,5 +1,68 @@ 'use strict'; +var levels = { + level: undefined, + friends: undefined +}; + +function functionCompareByName(friend, friendNext) { + + return friend.name > friendNext.name ? 1 : -1; +} + +function choiceFriendsOnLevel(friends) { + var friendsBest = Object.create(levels); + var sortFriends = []; + var namesPeopleChoiceFriends = []; + var noInviteFriends = []; + var nameChoiceFriends = []; + friendsBest.level = 0; + friendsBest.friends =friends.filter(function (item) { + if (item.best !== undefined) { + choiceFriend(item, namesPeopleChoiceFriends); + nameChoiceFriends.push(item.name); + return true; + } + noInviteFriends.push(item); + + return false; + }).sort(functionCompareByName); + sortFriends.push(friendsBest); + var iteration = 1; + while (nameChoiceFriends.length !== friends.length) { + var friendsLevel = Object.create(levels); + friendsLevel.level = iteration; + var choiceFriends = []; + var name = []; + noInviteFriends.forEach(function (item) { + var indexNamePeople = namesPeopleChoiceFriends.indexOf(item.name); + if (nameChoiceFriends.indexOf(item.name) === -1) { + if (indexNamePeople !== -1) { + choiceFriends.push(item); + nameChoiceFriends.push(item.name); + item.friends.forEach(function (nameFriendItem) { + name.push(nameFriendItem); + }); + } + } + }); + name.forEach(function (item) { + namesPeopleChoiceFriends.push(item); + }); + friendsLevel.friends = choiceFriends.sort(functionCompareByName); + sortFriends.push(friendsLevel); + iteration++; + } + + return sortFriends; +} + +function choiceFriend(item, namesPeopleChoiceFriends) { + item.friends.forEach(function (nameFriendItem) { + namesPeopleChoiceFriends.push(nameFriendItem); + }); +} + /** * Итератор по друзьям * @constructor @@ -8,8 +71,48 @@ */ function Iterator(friends, filter) { console.info(friends, filter); + if (!filter instanceof Filter) { + throw new TypeError('Filter не является прототипом filter'); + } + this.inviteFriends = function () { + + return filterFriendsByGender(choiceFriendsOnLevel(friends), filter, Infinity); + }; + this.indexFriend = 0; } +function filterFriendsByGender (friends, filter, maxLevel) { + var friendsFilter = []; + friends.forEach(function (item) { + item.friends.forEach(function (friend) { + if (filter.field(friend)) { + if (item.level < maxLevel) { + friendsFilter.push(friend); + } + } + }); + }); + + return friendsFilter; +} + +Iterator.prototype.done = function () { + + return this.indexFriend === this.inviteFriends().length; +}; + +Iterator.prototype.next = function () { + if (this.done()) { + + return null; + } + this.indexFriend++; + + return this.inviteFriends()[this.indexFriend-1]; +}; + + + /** * Итератор по друзям с ограничением по кругу * @extends Iterator @@ -20,16 +123,41 @@ function Iterator(friends, filter) { */ function LimitedIterator(friends, filter, maxLevel) { console.info(friends, filter, maxLevel); + this.inviteFriends = function () { + + return filterFriendsByGender(choiceFriendsOnLevel(friends), filter, maxLevel); + }; + this.indexFriend = 0; } +LimitedIterator.prototype = Object.create(Iterator.prototype); + +var allFilters = { + aFilter: true, + aMaleFilter: function (friend) { + + return friend.gender === 'male'; + }, + aFemaleFilter: function (friend) { + + return friend.gender === 'female'; + } +}; + /** * Фильтр друзей * @constructor */ function Filter() { console.info('Filter'); + this.field = allFilters.aFilter; } +Filter.prototype.apply = function () { + + return this.field.apply(null, arguments); +}; + /** * Фильтр друзей * @extends Filter @@ -37,8 +165,11 @@ function Filter() { */ function MaleFilter() { console.info('MaleFilter'); + this.field = allFilters.aMaleFilter; } +MaleFilter.prototype = Object.create(Filter.prototype); + /** * Фильтр друзей-девушек * @extends Filter @@ -46,8 +177,11 @@ function MaleFilter() { */ function FemaleFilter() { console.info('FemaleFilter'); + this.field = allFilters.aFemaleFilter; } +FemaleFilter.prototype = Object.create(Filter.prototype); + exports.Iterator = Iterator; exports.LimitedIterator = LimitedIterator; From 29b0221cb5954b5c43f2a1a6329e3dfcc6151949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Thu, 24 Nov 2016 00:32:24 +0500 Subject: [PATCH 02/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib.js b/lib.js index 2bea05b..b63b6c3 100644 --- a/lib.js +++ b/lib.js @@ -17,10 +17,11 @@ function choiceFriendsOnLevel(friends) { var noInviteFriends = []; var nameChoiceFriends = []; friendsBest.level = 0; - friendsBest.friends =friends.filter(function (item) { + friendsBest.friends = friends.filter(function (item) { if (item.best !== undefined) { choiceFriend(item, namesPeopleChoiceFriends); nameChoiceFriends.push(item.name); + return true; } noInviteFriends.push(item); @@ -34,18 +35,19 @@ function choiceFriendsOnLevel(friends) { friendsLevel.level = iteration; var choiceFriends = []; var name = []; - noInviteFriends.forEach(function (item) { - var indexNamePeople = namesPeopleChoiceFriends.indexOf(item.name); - if (nameChoiceFriends.indexOf(item.name) === -1) { + for (var index = 0; index < noInviteFriends.length; index++) { + //noInviteFriends.forEach(function (item) { + var indexNamePeople = namesPeopleChoiceFriends.indexOf(noInviteFriends[index].name); + if (nameChoiceFriends.indexOf(noInviteFriends[index].name) === -1) { if (indexNamePeople !== -1) { - choiceFriends.push(item); - nameChoiceFriends.push(item.name); - item.friends.forEach(function (nameFriendItem) { + choiceFriends.push(noInviteFriends[index]); + nameChoiceFriends.push(noInviteFriends[index].name); + noInviteFriends[index].friends.forEach(function (nameFriendItem) { name.push(nameFriendItem); }); } } - }); + } name.forEach(function (item) { namesPeopleChoiceFriends.push(item); }); @@ -71,7 +73,7 @@ function choiceFriend(item, namesPeopleChoiceFriends) { */ function Iterator(friends, filter) { console.info(friends, filter); - if (!filter instanceof Filter) { + if (!(filter instanceof Filter)) { throw new TypeError('Filter не является прототипом filter'); } this.inviteFriends = function () { @@ -108,11 +110,9 @@ Iterator.prototype.next = function () { } this.indexFriend++; - return this.inviteFriends()[this.indexFriend-1]; + return this.inviteFriends()[this.indexFriend - 1]; }; - - /** * Итератор по друзям с ограничением по кругу * @extends Iterator From e4dfb8076cb11a4ef0d9d424974bb99c25b133cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Thu, 24 Nov 2016 00:39:42 +0500 Subject: [PATCH 03/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib.js b/lib.js index b63b6c3..9e27b33 100644 --- a/lib.js +++ b/lib.js @@ -35,19 +35,7 @@ function choiceFriendsOnLevel(friends) { friendsLevel.level = iteration; var choiceFriends = []; var name = []; - for (var index = 0; index < noInviteFriends.length; index++) { - //noInviteFriends.forEach(function (item) { - var indexNamePeople = namesPeopleChoiceFriends.indexOf(noInviteFriends[index].name); - if (nameChoiceFriends.indexOf(noInviteFriends[index].name) === -1) { - if (indexNamePeople !== -1) { - choiceFriends.push(noInviteFriends[index]); - nameChoiceFriends.push(noInviteFriends[index].name); - noInviteFriends[index].friends.forEach(function (nameFriendItem) { - name.push(nameFriendItem); - }); - } - } - } + inspection(noInviteFriends, namesPeopleChoiceFriends, nameChoiceFriends, choiceFriends, name); name.forEach(function (item) { namesPeopleChoiceFriends.push(item); }); @@ -59,6 +47,21 @@ function choiceFriendsOnLevel(friends) { return sortFriends; } +function inspection(noInviteFriends, namesPeopleChoiceFriends, nameChoiceFriends, choiceFriends, name) { + for (var index = 0; index < noInviteFriends.length; index++) { + var indexNamePeople = namesPeopleChoiceFriends.indexOf(noInviteFriends[index].name); + if (nameChoiceFriends.indexOf(noInviteFriends[index].name) === -1) { + if (indexNamePeople !== -1) { + choiceFriends.push(noInviteFriends[index]); + nameChoiceFriends.push(noInviteFriends[index].name); + noInviteFriends[index].friends.forEach(function (nameFriendItem) { + name.push(nameFriendItem); + }); + } + } + } +} + function choiceFriend(item, namesPeopleChoiceFriends) { item.friends.forEach(function (nameFriendItem) { namesPeopleChoiceFriends.push(nameFriendItem); @@ -83,7 +86,7 @@ function Iterator(friends, filter) { this.indexFriend = 0; } -function filterFriendsByGender (friends, filter, maxLevel) { +function filterFriendsByGender(friends, filter, maxLevel) { var friendsFilter = []; friends.forEach(function (item) { item.friends.forEach(function (friend) { From 266377fb7b2404ac0cd86083a0eee84dfca58af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Thu, 24 Nov 2016 00:56:55 +0500 Subject: [PATCH 04/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/lib.js b/lib.js index 9e27b33..2ce1166 100644 --- a/lib.js +++ b/lib.js @@ -29,13 +29,35 @@ function choiceFriendsOnLevel(friends) { return false; }).sort(functionCompareByName); sortFriends.push(friendsBest); + var argument = [noInviteFriends, + namesPeopleChoiceFriends, + nameChoiceFriends, + sortFriends, + friends + ]; + findFriends(argument); + + return sortFriends; +} + +function findFriends(arg) { + var noInviteFriends = arg[0]; + var namesPeopleChoiceFriends = arg[1]; + var nameChoiceFriends = arg[2]; + var sortFriends = arg[3]; + var friends = arg[4]; var iteration = 1; while (nameChoiceFriends.length !== friends.length) { var friendsLevel = Object.create(levels); friendsLevel.level = iteration; var choiceFriends = []; var name = []; - inspection(noInviteFriends, namesPeopleChoiceFriends, nameChoiceFriends, choiceFriends, name); + var argument = [noInviteFriends, + namesPeopleChoiceFriends, + nameChoiceFriends, + choiceFriends, + name]; + inspection(argument); name.forEach(function (item) { namesPeopleChoiceFriends.push(item); }); @@ -43,21 +65,22 @@ function choiceFriendsOnLevel(friends) { sortFriends.push(friendsLevel); iteration++; } - - return sortFriends; } -function inspection(noInviteFriends, namesPeopleChoiceFriends, nameChoiceFriends, choiceFriends, name) { +function inspection(arg) { + var noInviteFriends = arg[0]; + var namesPeopleChoiceFriends = arg[1]; + var nameChoiceFriends = arg[2]; + var choiceFriends = arg[3]; + var name = arg[4]; for (var index = 0; index < noInviteFriends.length; index++) { var indexNamePeople = namesPeopleChoiceFriends.indexOf(noInviteFriends[index].name); - if (nameChoiceFriends.indexOf(noInviteFriends[index].name) === -1) { - if (indexNamePeople !== -1) { - choiceFriends.push(noInviteFriends[index]); - nameChoiceFriends.push(noInviteFriends[index].name); - noInviteFriends[index].friends.forEach(function (nameFriendItem) { - name.push(nameFriendItem); - }); - } + if (nameChoiceFriends.indexOf(noInviteFriends[index].name) === -1 && indexNamePeople !== -1) { + choiceFriends.push(noInviteFriends[index]); + nameChoiceFriends.push(noInviteFriends[index].name); + noInviteFriends[index].friends.forEach(function (nameFriendItem) { + name.push(nameFriendItem); + }); } } } From a1be98bd9515627c29aee50785b1fc5eba531f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Thu, 24 Nov 2016 01:06:16 +0500 Subject: [PATCH 05/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/lib.js b/lib.js index 2ce1166..f365534 100644 --- a/lib.js +++ b/lib.js @@ -31,21 +31,17 @@ function choiceFriendsOnLevel(friends) { sortFriends.push(friendsBest); var argument = [noInviteFriends, namesPeopleChoiceFriends, - nameChoiceFriends, - sortFriends, - friends + nameChoiceFriends ]; - findFriends(argument); + findFriends(argument, friends, sortFriends); return sortFriends; } -function findFriends(arg) { +function findFriends(arg, friends, sortFriends) { var noInviteFriends = arg[0]; var namesPeopleChoiceFriends = arg[1]; var nameChoiceFriends = arg[2]; - var sortFriends = arg[3]; - var friends = arg[4]; var iteration = 1; while (nameChoiceFriends.length !== friends.length) { var friendsLevel = Object.create(levels); @@ -58,9 +54,6 @@ function findFriends(arg) { choiceFriends, name]; inspection(argument); - name.forEach(function (item) { - namesPeopleChoiceFriends.push(item); - }); friendsLevel.friends = choiceFriends.sort(functionCompareByName); sortFriends.push(friendsLevel); iteration++; @@ -73,16 +66,19 @@ function inspection(arg) { var nameChoiceFriends = arg[2]; var choiceFriends = arg[3]; var name = arg[4]; - for (var index = 0; index < noInviteFriends.length; index++) { - var indexNamePeople = namesPeopleChoiceFriends.indexOf(noInviteFriends[index].name); - if (nameChoiceFriends.indexOf(noInviteFriends[index].name) === -1 && indexNamePeople !== -1) { - choiceFriends.push(noInviteFriends[index]); - nameChoiceFriends.push(noInviteFriends[index].name); - noInviteFriends[index].friends.forEach(function (nameFriendItem) { + for (var i = 0; i < noInviteFriends.length; i++) { + var indexNamePeople = namesPeopleChoiceFriends.indexOf(noInviteFriends[i].name); + if (nameChoiceFriends.indexOf(noInviteFriends[i].name) === -1 && indexNamePeople !== -1) { + choiceFriends.push(noInviteFriends[i]); + nameChoiceFriends.push(noInviteFriends[i].name); + noInviteFriends[i].friends.forEach(function (nameFriendItem) { name.push(nameFriendItem); }); } } + name.forEach(function (item) { + namesPeopleChoiceFriends.push(item); + }); } function choiceFriend(item, namesPeopleChoiceFriends) { From 5b03023eb555b5f81aa8833e286f18149966b4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 26 Nov 2016 17:35:06 +0500 Subject: [PATCH 06/40] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=20=D0=BD=D0=B5?= =?UTF-8?q?=D1=81=D0=B2=D1=8F=D0=B7=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B4?= =?UTF-8?q?=D1=80=D1=83=D0=B7=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib.js b/lib.js index f365534..4841acc 100644 --- a/lib.js +++ b/lib.js @@ -10,15 +10,33 @@ function functionCompareByName(friend, friendNext) { return friend.name > friendNext.name ? 1 : -1; } -function choiceFriendsOnLevel(friends) { +function onlyConnectedFriends(allFriends) { + var allFriendsFriends = []; + allFriends.forEach(function (item) { + item.friends.forEach(function (friendItem) { + allFriendsFriends.push(friendItem); + }); + }); + + return allFriends.filter(function (item) { + if (!item.best) { + + return allFriendsFriends.indexOf(item.name) !== -1; + } + + return true; + }); +} + +function choiceFriendsOnLevel(allFriends) { var friendsBest = Object.create(levels); var sortFriends = []; var namesPeopleChoiceFriends = []; var noInviteFriends = []; var nameChoiceFriends = []; friendsBest.level = 0; - friendsBest.friends = friends.filter(function (item) { - if (item.best !== undefined) { + friendsBest.friends = allFriends.filter(function (item) { + if (item.best) { choiceFriend(item, namesPeopleChoiceFriends); nameChoiceFriends.push(item.name); @@ -28,6 +46,7 @@ function choiceFriendsOnLevel(friends) { return false; }).sort(functionCompareByName); + var friends = onlyConnectedFriends(allFriends); sortFriends.push(friendsBest); var argument = [noInviteFriends, namesPeopleChoiceFriends, From dc4e6183c3cd50a079cb94e855db792bcc989f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 26 Nov 2016 18:13:03 +0500 Subject: [PATCH 07/40] =?UTF-8?q?=D0=BD=D0=B0=D1=81=D0=BB=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib.js b/lib.js index 4841acc..bee47ea 100644 --- a/lib.js +++ b/lib.js @@ -117,9 +117,13 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Filter не является прототипом filter'); } + this.friendsSort = function () { + + return choiceFriendsOnLevel(friends); + }; this.inviteFriends = function () { - return filterFriendsByGender(choiceFriendsOnLevel(friends), filter, Infinity); + return filterFriendsByGender(this.friendsSort(), filter, Infinity); }; this.indexFriend = 0; } @@ -164,9 +168,11 @@ Iterator.prototype.next = function () { */ function LimitedIterator(friends, filter, maxLevel) { console.info(friends, filter, maxLevel); + Iterator.call(this, friends, filter); this.inviteFriends = function () { - return filterFriendsByGender(choiceFriendsOnLevel(friends), filter, maxLevel); + // return filterFriendsByGender(choiceFriendsOnLevel(friends), filter, maxLevel); + return filterFriendsByGender(this.friendsSort(), filter, maxLevel); }; this.indexFriend = 0; } From 7776559ddb38d97710b1f4b2f5210c9dabe2e730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 26 Nov 2016 20:34:04 +0500 Subject: [PATCH 08/40] =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=82=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 81 +++++++++++++++++++++++++--------------------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/lib.js b/lib.js index bee47ea..f6f473e 100644 --- a/lib.js +++ b/lib.js @@ -18,14 +18,7 @@ function onlyConnectedFriends(allFriends) { }); }); - return allFriends.filter(function (item) { - if (!item.best) { - - return allFriendsFriends.indexOf(item.name) !== -1; - } - - return true; - }); + return allFriendsFriends; } function choiceFriendsOnLevel(allFriends) { @@ -35,18 +28,29 @@ function choiceFriendsOnLevel(allFriends) { var noInviteFriends = []; var nameChoiceFriends = []; friendsBest.level = 0; + var namesAllPeople = onlyConnectedFriends(allFriends); + var friends = []; + var levelWithName = Object.create(levels); + levelWithName.level = 0; + var friendsFriendsOnLevel = []; friendsBest.friends = allFriends.filter(function (item) { if (item.best) { - choiceFriend(item, namesPeopleChoiceFriends); + + choiceFriend(item, friendsFriendsOnLevel, nameChoiceFriends); nameChoiceFriends.push(item.name); + friends.push(item); return true; } - noInviteFriends.push(item); + if (namesAllPeople.indexOf(item.name) !== -1) { + friends.push(item); + noInviteFriends.push(item); + } return false; }).sort(functionCompareByName); - var friends = onlyConnectedFriends(allFriends); + levelWithName.friends = friendsFriendsOnLevel; + namesPeopleChoiceFriends.push(levelWithName); sortFriends.push(friendsBest); var argument = [noInviteFriends, namesPeopleChoiceFriends, @@ -66,43 +70,42 @@ function findFriends(arg, friends, sortFriends) { var friendsLevel = Object.create(levels); friendsLevel.level = iteration; var choiceFriends = []; - var name = []; var argument = [noInviteFriends, namesPeopleChoiceFriends, nameChoiceFriends, - choiceFriends, - name]; - inspection(argument); + choiceFriends]; + inspection(argument, iteration); friendsLevel.friends = choiceFriends.sort(functionCompareByName); sortFriends.push(friendsLevel); iteration++; } } -function inspection(arg) { +function inspection(arg, iteration) { var noInviteFriends = arg[0]; var namesPeopleChoiceFriends = arg[1]; var nameChoiceFriends = arg[2]; var choiceFriends = arg[3]; - var name = arg[4]; + var name = []; + var levelWithName = Object.create(levels); + levelWithName.level = iteration; for (var i = 0; i < noInviteFriends.length; i++) { - var indexNamePeople = namesPeopleChoiceFriends.indexOf(noInviteFriends[i].name); + var indexNamePeople = namesPeopleChoiceFriends[iteration-1].friends.indexOf(noInviteFriends[i].name); if (nameChoiceFriends.indexOf(noInviteFriends[i].name) === -1 && indexNamePeople !== -1) { choiceFriends.push(noInviteFriends[i]); nameChoiceFriends.push(noInviteFriends[i].name); - noInviteFriends[i].friends.forEach(function (nameFriendItem) { - name.push(nameFriendItem); - }); + choiceFriend(noInviteFriends[i], name, nameChoiceFriends); } } - name.forEach(function (item) { - namesPeopleChoiceFriends.push(item); - }); + levelWithName.friends = name; + namesPeopleChoiceFriends.push(levelWithName); } -function choiceFriend(item, namesPeopleChoiceFriends) { +function choiceFriend(item, friendsFriendsOnLevel, nameChoiceFriends) { item.friends.forEach(function (nameFriendItem) { - namesPeopleChoiceFriends.push(nameFriendItem); + if (nameChoiceFriends.indexOf(nameFriendItem) === -1) { + friendsFriendsOnLevel.push(nameFriendItem); + } }); } @@ -113,18 +116,12 @@ function choiceFriend(item, namesPeopleChoiceFriends) { * @param {Filter} filter */ function Iterator(friends, filter) { - console.info(friends, filter); if (!(filter instanceof Filter)) { throw new TypeError('Filter не является прототипом filter'); } - this.friendsSort = function () { - - return choiceFriendsOnLevel(friends); - }; - this.inviteFriends = function () { - - return filterFriendsByGender(this.friendsSort(), filter, Infinity); - }; + var workWithFriends = choiceFriendsOnLevel(friends); + this.friendsSort = workWithFriends; + this.inviteFriends = filterFriendsByGender(this.friendsSort, filter, Infinity); this.indexFriend = 0; } @@ -145,7 +142,7 @@ function filterFriendsByGender(friends, filter, maxLevel) { Iterator.prototype.done = function () { - return this.indexFriend === this.inviteFriends().length; + return this.indexFriend === this.inviteFriends.length; }; Iterator.prototype.next = function () { @@ -155,7 +152,7 @@ Iterator.prototype.next = function () { } this.indexFriend++; - return this.inviteFriends()[this.indexFriend - 1]; + return this.inviteFriends[this.indexFriend - 1]; }; /** @@ -167,13 +164,8 @@ Iterator.prototype.next = function () { * @param {Number} maxLevel – максимальный круг друзей */ function LimitedIterator(friends, filter, maxLevel) { - console.info(friends, filter, maxLevel); Iterator.call(this, friends, filter); - this.inviteFriends = function () { - - // return filterFriendsByGender(choiceFriendsOnLevel(friends), filter, maxLevel); - return filterFriendsByGender(this.friendsSort(), filter, maxLevel); - }; + this.inviteFriends = filterFriendsByGender(this.friendsSort, filter, maxLevel); this.indexFriend = 0; } @@ -196,7 +188,6 @@ var allFilters = { * @constructor */ function Filter() { - console.info('Filter'); this.field = allFilters.aFilter; } @@ -211,7 +202,6 @@ Filter.prototype.apply = function () { * @constructor */ function MaleFilter() { - console.info('MaleFilter'); this.field = allFilters.aMaleFilter; } @@ -223,7 +213,6 @@ MaleFilter.prototype = Object.create(Filter.prototype); * @constructor */ function FemaleFilter() { - console.info('FemaleFilter'); this.field = allFilters.aFemaleFilter; } From 4b1ab779d48e9bb77642cfb2c9b82237490322dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 26 Nov 2016 20:49:38 +0500 Subject: [PATCH 09/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/lib.js b/lib.js index f6f473e..3e350d8 100644 --- a/lib.js +++ b/lib.js @@ -21,6 +21,27 @@ function onlyConnectedFriends(allFriends) { return allFriendsFriends; } +function findBestFriends(arg, friends) { + var item = arg[0]; + var friendsFriendsOnLevel = arg[1]; + var nameChoiceFriends = arg[2]; + var namesAllPeople = arg[3]; + var noInviteFriends = arg[4]; + if (item.best) { + choiceFriend(item, friendsFriendsOnLevel, nameChoiceFriends); + nameChoiceFriends.push(item.name); + friends.push(item); + + return true; + } + if (namesAllPeople.indexOf(item.name) !== -1) { + friends.push(item); + noInviteFriends.push(item); + } + + return false; +} + function choiceFriendsOnLevel(allFriends) { var friendsBest = Object.create(levels); var sortFriends = []; @@ -34,20 +55,14 @@ function choiceFriendsOnLevel(allFriends) { levelWithName.level = 0; var friendsFriendsOnLevel = []; friendsBest.friends = allFriends.filter(function (item) { - if (item.best) { - - choiceFriend(item, friendsFriendsOnLevel, nameChoiceFriends); - nameChoiceFriends.push(item.name); - friends.push(item); - - return true; - } - if (namesAllPeople.indexOf(item.name) !== -1) { - friends.push(item); - noInviteFriends.push(item); - } - - return false; + var argument = [item, + friendsFriendsOnLevel, + nameChoiceFriends, + namesAllPeople, + noInviteFriends + ]; + + return findBestFriends(argument, friends); }).sort(functionCompareByName); levelWithName.friends = friendsFriendsOnLevel; namesPeopleChoiceFriends.push(levelWithName); @@ -90,7 +105,8 @@ function inspection(arg, iteration) { var levelWithName = Object.create(levels); levelWithName.level = iteration; for (var i = 0; i < noInviteFriends.length; i++) { - var indexNamePeople = namesPeopleChoiceFriends[iteration-1].friends.indexOf(noInviteFriends[i].name); + var namesFriendLevel = namesPeopleChoiceFriends[iteration - 1].friends; + var indexNamePeople = namesFriendLevel.indexOf(noInviteFriends[i].name); if (nameChoiceFriends.indexOf(noInviteFriends[i].name) === -1 && indexNamePeople !== -1) { choiceFriends.push(noInviteFriends[i]); nameChoiceFriends.push(noInviteFriends[i].name); From 7cf4531bb43d58b52d176a9589afe8c9f111fe09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 26 Nov 2016 21:35:27 +0500 Subject: [PATCH 10/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib.js b/lib.js index 3e350d8..596f4da 100644 --- a/lib.js +++ b/lib.js @@ -21,12 +21,11 @@ function onlyConnectedFriends(allFriends) { return allFriendsFriends; } -function findBestFriends(arg, friends) { +function findBestFriends(arg, friends, noInviteFriends) { var item = arg[0]; var friendsFriendsOnLevel = arg[1]; var nameChoiceFriends = arg[2]; var namesAllPeople = arg[3]; - var noInviteFriends = arg[4]; if (item.best) { choiceFriend(item, friendsFriendsOnLevel, nameChoiceFriends); nameChoiceFriends.push(item.name); @@ -58,19 +57,16 @@ function choiceFriendsOnLevel(allFriends) { var argument = [item, friendsFriendsOnLevel, nameChoiceFriends, - namesAllPeople, - noInviteFriends - ]; + namesAllPeople]; - return findBestFriends(argument, friends); + return findBestFriends(argument, friends, noInviteFriends); }).sort(functionCompareByName); levelWithName.friends = friendsFriendsOnLevel; namesPeopleChoiceFriends.push(levelWithName); sortFriends.push(friendsBest); var argument = [noInviteFriends, namesPeopleChoiceFriends, - nameChoiceFriends - ]; + nameChoiceFriends]; findFriends(argument, friends, sortFriends); return sortFriends; @@ -87,20 +83,18 @@ function findFriends(arg, friends, sortFriends) { var choiceFriends = []; var argument = [noInviteFriends, namesPeopleChoiceFriends, - nameChoiceFriends, - choiceFriends]; - inspection(argument, iteration); + nameChoiceFriends]; + inspection(argument, iteration, choiceFriends); friendsLevel.friends = choiceFriends.sort(functionCompareByName); sortFriends.push(friendsLevel); iteration++; } } -function inspection(arg, iteration) { +function inspection(arg, iteration, choiceFriends) { var noInviteFriends = arg[0]; var namesPeopleChoiceFriends = arg[1]; var nameChoiceFriends = arg[2]; - var choiceFriends = arg[3]; var name = []; var levelWithName = Object.create(levels); levelWithName.level = iteration; From 93deec7788b7e292ad8db688cfd82c5ebb4fd0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 26 Nov 2016 22:12:15 +0500 Subject: [PATCH 11/40] statement --- lib.js | 61 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/lib.js b/lib.js index 596f4da..92c9de6 100644 --- a/lib.js +++ b/lib.js @@ -21,24 +21,32 @@ function onlyConnectedFriends(allFriends) { return allFriendsFriends; } -function findBestFriends(arg, friends, noInviteFriends) { - var item = arg[0]; - var friendsFriendsOnLevel = arg[1]; - var nameChoiceFriends = arg[2]; - var namesAllPeople = arg[3]; - if (item.best) { - choiceFriend(item, friendsFriendsOnLevel, nameChoiceFriends); - nameChoiceFriends.push(item.name); - friends.push(item); +function findBestFriends(arg, allFriends, noInviteFriends) { + var nameChoiceFriends = arg[0]; + var namesAllPeople = arg[1]; + var friendsBest = arg[2]; + var levelWithName = arg[3]; + var friends = []; + var friendsFriendsOnLevel = []; + friendsBest.friends = allFriends.filter(function (item) { + if (item.best) { + choiceFriend(item, friendsFriendsOnLevel, nameChoiceFriends); + nameChoiceFriends.push(item.name); + friends.push(item); - return true; - } - if (namesAllPeople.indexOf(item.name) !== -1) { - friends.push(item); - noInviteFriends.push(item); - } + return true; + } + if (namesAllPeople.indexOf(item.name) !== -1) { + friends.push(item); + noInviteFriends.push(item); + } + + return false; - return false; + }).sort(functionCompareByName); + levelWithName.friends = friendsFriendsOnLevel; + + return friends; } function choiceFriendsOnLevel(allFriends) { @@ -49,25 +57,20 @@ function choiceFriendsOnLevel(allFriends) { var nameChoiceFriends = []; friendsBest.level = 0; var namesAllPeople = onlyConnectedFriends(allFriends); - var friends = []; var levelWithName = Object.create(levels); levelWithName.level = 0; - var friendsFriendsOnLevel = []; - friendsBest.friends = allFriends.filter(function (item) { - var argument = [item, - friendsFriendsOnLevel, - nameChoiceFriends, - namesAllPeople]; - - return findBestFriends(argument, friends, noInviteFriends); - }).sort(functionCompareByName); - levelWithName.friends = friendsFriendsOnLevel; + var argument1 = [ + nameChoiceFriends, + namesAllPeople, + friendsBest, + levelWithName]; + var friends = findBestFriends(argument1, allFriends, noInviteFriends); namesPeopleChoiceFriends.push(levelWithName); sortFriends.push(friendsBest); - var argument = [noInviteFriends, + var argument2 = [noInviteFriends, namesPeopleChoiceFriends, nameChoiceFriends]; - findFriends(argument, friends, sortFriends); + findFriends(argument2, friends, sortFriends); return sortFriends; } From 07642bca723f0c330129cd8ba507455d118396aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 26 Nov 2016 22:18:26 +0500 Subject: [PATCH 12/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib.js b/lib.js index 92c9de6..81c31bb 100644 --- a/lib.js +++ b/lib.js @@ -25,9 +25,11 @@ function findBestFriends(arg, allFriends, noInviteFriends) { var nameChoiceFriends = arg[0]; var namesAllPeople = arg[1]; var friendsBest = arg[2]; - var levelWithName = arg[3]; + var namesPeopleChoiceFriends = arg[3]; var friends = []; var friendsFriendsOnLevel = []; + var levelWithName = Object.create(levels); + levelWithName.level = 0; friendsBest.friends = allFriends.filter(function (item) { if (item.best) { choiceFriend(item, friendsFriendsOnLevel, nameChoiceFriends); @@ -45,6 +47,7 @@ function findBestFriends(arg, allFriends, noInviteFriends) { }).sort(functionCompareByName); levelWithName.friends = friendsFriendsOnLevel; + namesPeopleChoiceFriends.push(levelWithName); return friends; } @@ -57,15 +60,11 @@ function choiceFriendsOnLevel(allFriends) { var nameChoiceFriends = []; friendsBest.level = 0; var namesAllPeople = onlyConnectedFriends(allFriends); - var levelWithName = Object.create(levels); - levelWithName.level = 0; - var argument1 = [ - nameChoiceFriends, - namesAllPeople, - friendsBest, - levelWithName]; + var argument1 = [nameChoiceFriends, + namesAllPeople, + friendsBest, + namesPeopleChoiceFriends]; var friends = findBestFriends(argument1, allFriends, noInviteFriends); - namesPeopleChoiceFriends.push(levelWithName); sortFriends.push(friendsBest); var argument2 = [noInviteFriends, namesPeopleChoiceFriends, From 3a09b518cabe632fa5b3c5d43207a220b852da70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sun, 27 Nov 2016 00:18:40 +0500 Subject: [PATCH 13/40] level --- lib.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib.js b/lib.js index 81c31bb..0a23965 100644 --- a/lib.js +++ b/lib.js @@ -131,22 +131,23 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Filter не является прототипом filter'); } + var maxLevel = arguments[2] === undefined ? Infinity : arguments[2]; var workWithFriends = choiceFriendsOnLevel(friends); this.friendsSort = workWithFriends; - this.inviteFriends = filterFriendsByGender(this.friendsSort, filter, Infinity); + this.inviteFriends = filterFriendsByGender(this.friendsSort, filter, maxLevel); this.indexFriend = 0; } function filterFriendsByGender(friends, filter, maxLevel) { var friendsFilter = []; friends.forEach(function (item) { - item.friends.forEach(function (friend) { - if (filter.field(friend)) { - if (item.level < maxLevel) { + if (item.level < maxLevel) { + item.friends.forEach(function (friend) { + if (filter.field(friend)) { friendsFilter.push(friend); } - } - }); + }); + } }); return friendsFilter; @@ -176,9 +177,7 @@ Iterator.prototype.next = function () { * @param {Number} maxLevel – максимальный круг друзей */ function LimitedIterator(friends, filter, maxLevel) { - Iterator.call(this, friends, filter); - this.inviteFriends = filterFriendsByGender(this.friendsSort, filter, maxLevel); - this.indexFriend = 0; + Iterator.call(this, friends, filter, maxLevel); } LimitedIterator.prototype = Object.create(Iterator.prototype); From 7f5b4d7bc0c288666054bcd4c081dc24aaefda3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 00:52:38 +0500 Subject: [PATCH 14/40] =?UTF-8?q?=D0=BE=D0=BF=D1=82=D0=B8=D0=BC=D0=B8?= =?UTF-8?q?=D0=B7=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 99 +++++++++++++++++++++++++--------------------------------- 1 file changed, 42 insertions(+), 57 deletions(-) diff --git a/lib.js b/lib.js index 0a23965..50c8784 100644 --- a/lib.js +++ b/lib.js @@ -2,7 +2,8 @@ var levels = { level: undefined, - friends: undefined + friends: undefined, + names: undefined }; function functionCompareByName(friend, friendNext) { @@ -22,18 +23,14 @@ function onlyConnectedFriends(allFriends) { } function findBestFriends(arg, allFriends, noInviteFriends) { - var nameChoiceFriends = arg[0]; - var namesAllPeople = arg[1]; - var friendsBest = arg[2]; - var namesPeopleChoiceFriends = arg[3]; + var namesAllPeople = arg[0]; + var friendsOnLevel = arg[1]; + var namesPeopleChoiceFriends = arg[2]; var friends = []; var friendsFriendsOnLevel = []; - var levelWithName = Object.create(levels); - levelWithName.level = 0; - friendsBest.friends = allFriends.filter(function (item) { + friendsOnLevel.friends = allFriends.filter(function (item) { if (item.best) { - choiceFriend(item, friendsFriendsOnLevel, nameChoiceFriends); - nameChoiceFriends.push(item.name); + choiceFriend(item, friendsFriendsOnLevel); friends.push(item); return true; @@ -46,46 +43,39 @@ function findBestFriends(arg, allFriends, noInviteFriends) { return false; }).sort(functionCompareByName); - levelWithName.friends = friendsFriendsOnLevel; - namesPeopleChoiceFriends.push(levelWithName); + friendsOnLevel.names = friendsFriendsOnLevel; return friends; } -function choiceFriendsOnLevel(allFriends) { - var friendsBest = Object.create(levels); +function choiceFriendsOnLevel(allFriends, maxLevel) { + var friendsOnLevel = Object.create(levels); var sortFriends = []; - var namesPeopleChoiceFriends = []; var noInviteFriends = []; - var nameChoiceFriends = []; - friendsBest.level = 0; + friendsOnLevel.level = 0; var namesAllPeople = onlyConnectedFriends(allFriends); - var argument1 = [nameChoiceFriends, - namesAllPeople, - friendsBest, - namesPeopleChoiceFriends]; + var argument1 = [namesAllPeople, friendsOnLevel]; var friends = findBestFriends(argument1, allFriends, noInviteFriends); - sortFriends.push(friendsBest); - var argument2 = [noInviteFriends, - namesPeopleChoiceFriends, - nameChoiceFriends]; - findFriends(argument2, friends, sortFriends); + sortFriends.push(friendsOnLevel); + var argument2 = [noInviteFriends, friends, sortFriends]; + findFriends(argument2, maxLevel); return sortFriends; } -function findFriends(arg, friends, sortFriends) { +function findFriends(arg, maxLevel) { var noInviteFriends = arg[0]; - var namesPeopleChoiceFriends = arg[1]; - var nameChoiceFriends = arg[2]; + var friends = arg[1]; + var sortFriends = arg[2]; var iteration = 1; - while (nameChoiceFriends.length !== friends.length) { + while(noInviteFriends.length !== 0) { + if (iteration === maxLevel) { + break; + } var friendsLevel = Object.create(levels); friendsLevel.level = iteration; var choiceFriends = []; - var argument = [noInviteFriends, - namesPeopleChoiceFriends, - nameChoiceFriends]; + var argument = [noInviteFriends, sortFriends, friendsLevel]; inspection(argument, iteration, choiceFriends); friendsLevel.friends = choiceFriends.sort(functionCompareByName); sortFriends.push(friendsLevel); @@ -95,27 +85,25 @@ function findFriends(arg, friends, sortFriends) { function inspection(arg, iteration, choiceFriends) { var noInviteFriends = arg[0]; - var namesPeopleChoiceFriends = arg[1]; - var nameChoiceFriends = arg[2]; - var name = []; - var levelWithName = Object.create(levels); - levelWithName.level = iteration; + var sortFriends = arg[1]; + var friendsLevel = arg[2]; + var namesFriends = []; for (var i = 0; i < noInviteFriends.length; i++) { - var namesFriendLevel = namesPeopleChoiceFriends[iteration - 1].friends; + var namesFriendLevel = sortFriends[iteration-1].names; var indexNamePeople = namesFriendLevel.indexOf(noInviteFriends[i].name); - if (nameChoiceFriends.indexOf(noInviteFriends[i].name) === -1 && indexNamePeople !== -1) { + if (indexNamePeople !== -1) { choiceFriends.push(noInviteFriends[i]); - nameChoiceFriends.push(noInviteFriends[i].name); - choiceFriend(noInviteFriends[i], name, nameChoiceFriends); + choiceFriend(noInviteFriends[i], namesFriends); + noInviteFriends.splice(i, 1); + i--; } } - levelWithName.friends = name; - namesPeopleChoiceFriends.push(levelWithName); + friendsLevel.names = namesFriends; } -function choiceFriend(item, friendsFriendsOnLevel, nameChoiceFriends) { +function choiceFriend(item, friendsFriendsOnLevel) { item.friends.forEach(function (nameFriendItem) { - if (nameChoiceFriends.indexOf(nameFriendItem) === -1) { + if (friendsFriendsOnLevel.indexOf(item.name) === -1) { friendsFriendsOnLevel.push(nameFriendItem); } }); @@ -132,22 +120,19 @@ function Iterator(friends, filter) { throw new TypeError('Filter не является прототипом filter'); } var maxLevel = arguments[2] === undefined ? Infinity : arguments[2]; - var workWithFriends = choiceFriendsOnLevel(friends); - this.friendsSort = workWithFriends; - this.inviteFriends = filterFriendsByGender(this.friendsSort, filter, maxLevel); + var workWithFriends = choiceFriendsOnLevel(friends, maxLevel); + this.inviteFriends = filterFriendsByGender(workWithFriends, filter); this.indexFriend = 0; } -function filterFriendsByGender(friends, filter, maxLevel) { +function filterFriendsByGender(friends, filter) { var friendsFilter = []; friends.forEach(function (item) { - if (item.level < maxLevel) { - item.friends.forEach(function (friend) { - if (filter.field(friend)) { - friendsFilter.push(friend); - } - }); - } + item.friends.forEach(function (friend) { + if (filter.field(friend)) { + friendsFilter.push(friend); + } + }); }); return friendsFilter; From 474c1b98f67edfa874d0bea428f9b1ff5cd55297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 00:58:21 +0500 Subject: [PATCH 15/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib.js b/lib.js index 50c8784..846a1ce 100644 --- a/lib.js +++ b/lib.js @@ -25,7 +25,6 @@ function onlyConnectedFriends(allFriends) { function findBestFriends(arg, allFriends, noInviteFriends) { var namesAllPeople = arg[0]; var friendsOnLevel = arg[1]; - var namesPeopleChoiceFriends = arg[2]; var friends = []; var friendsFriendsOnLevel = []; friendsOnLevel.friends = allFriends.filter(function (item) { @@ -57,7 +56,7 @@ function choiceFriendsOnLevel(allFriends, maxLevel) { var argument1 = [namesAllPeople, friendsOnLevel]; var friends = findBestFriends(argument1, allFriends, noInviteFriends); sortFriends.push(friendsOnLevel); - var argument2 = [noInviteFriends, friends, sortFriends]; + var argument2 = [noInviteFriends, sortFriends]; findFriends(argument2, maxLevel); return sortFriends; @@ -65,10 +64,9 @@ function choiceFriendsOnLevel(allFriends, maxLevel) { function findFriends(arg, maxLevel) { var noInviteFriends = arg[0]; - var friends = arg[1]; - var sortFriends = arg[2]; + var sortFriends = arg[1]; var iteration = 1; - while(noInviteFriends.length !== 0) { + while (noInviteFriends.length !== 0) { if (iteration === maxLevel) { break; } @@ -89,8 +87,7 @@ function inspection(arg, iteration, choiceFriends) { var friendsLevel = arg[2]; var namesFriends = []; for (var i = 0; i < noInviteFriends.length; i++) { - var namesFriendLevel = sortFriends[iteration-1].names; - var indexNamePeople = namesFriendLevel.indexOf(noInviteFriends[i].name); + var indexNamePeople = sortFriends[iteration-1].names.indexOf(noInviteFriends[i].name; if (indexNamePeople !== -1) { choiceFriends.push(noInviteFriends[i]); choiceFriend(noInviteFriends[i], namesFriends); From 8ff0512dca4e7bfab492e36b7b503931c5f69588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 01:05:07 +0500 Subject: [PATCH 16/40] =?UTF-8?q?=D0=BD=D0=B5=D1=85=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D1=81=D0=BA=D0=BE=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.js b/lib.js index 846a1ce..6869c6e 100644 --- a/lib.js +++ b/lib.js @@ -87,7 +87,7 @@ function inspection(arg, iteration, choiceFriends) { var friendsLevel = arg[2]; var namesFriends = []; for (var i = 0; i < noInviteFriends.length; i++) { - var indexNamePeople = sortFriends[iteration-1].names.indexOf(noInviteFriends[i].name; + var indexNamePeople = sortFriends[iteration-1].names.indexOf(noInviteFriends[i].name); if (indexNamePeople !== -1) { choiceFriends.push(noInviteFriends[i]); choiceFriend(noInviteFriends[i], namesFriends); From e71fe5a8a9388f9a8f0a284b72a1737251a17858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 01:11:00 +0500 Subject: [PATCH 17/40] =?UTF-8?q?=D0=BB=D0=B8=D1=88=D0=BD=D1=8F=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib.js b/lib.js index 6869c6e..ab618e2 100644 --- a/lib.js +++ b/lib.js @@ -25,17 +25,14 @@ function onlyConnectedFriends(allFriends) { function findBestFriends(arg, allFriends, noInviteFriends) { var namesAllPeople = arg[0]; var friendsOnLevel = arg[1]; - var friends = []; var friendsFriendsOnLevel = []; friendsOnLevel.friends = allFriends.filter(function (item) { if (item.best) { choiceFriend(item, friendsFriendsOnLevel); - friends.push(item); return true; } if (namesAllPeople.indexOf(item.name) !== -1) { - friends.push(item); noInviteFriends.push(item); } @@ -43,8 +40,6 @@ function findBestFriends(arg, allFriends, noInviteFriends) { }).sort(functionCompareByName); friendsOnLevel.names = friendsFriendsOnLevel; - - return friends; } function choiceFriendsOnLevel(allFriends, maxLevel) { @@ -54,7 +49,7 @@ function choiceFriendsOnLevel(allFriends, maxLevel) { friendsOnLevel.level = 0; var namesAllPeople = onlyConnectedFriends(allFriends); var argument1 = [namesAllPeople, friendsOnLevel]; - var friends = findBestFriends(argument1, allFriends, noInviteFriends); + findBestFriends(argument1, allFriends, noInviteFriends); sortFriends.push(friendsOnLevel); var argument2 = [noInviteFriends, sortFriends]; findFriends(argument2, maxLevel); @@ -87,7 +82,7 @@ function inspection(arg, iteration, choiceFriends) { var friendsLevel = arg[2]; var namesFriends = []; for (var i = 0; i < noInviteFriends.length; i++) { - var indexNamePeople = sortFriends[iteration-1].names.indexOf(noInviteFriends[i].name); + var indexNamePeople = sortFriends[iteration - 1].names.indexOf(noInviteFriends[i].name); if (indexNamePeople !== -1) { choiceFriends.push(noInviteFriends[i]); choiceFriend(noInviteFriends[i], namesFriends); From d9f9ee3025e715bfab5ead5a2391c5b4425d0351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 15:50:58 +0500 Subject: [PATCH 18/40] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib.js b/lib.js index ab618e2..ac7447d 100644 --- a/lib.js +++ b/lib.js @@ -42,7 +42,15 @@ function findBestFriends(arg, allFriends, noInviteFriends) { friendsOnLevel.names = friendsFriendsOnLevel; } -function choiceFriendsOnLevel(allFriends, maxLevel) { +function choiceFriendsOnLevel(allFriends, maxLevel, filter) { + if (maxLevel === undefined || maxLevel === 0) { + if (filter.type === 'male') { + + return []; + } else { + maxLevel = Infinity; + } + } var friendsOnLevel = Object.create(levels); var sortFriends = []; var noInviteFriends = []; @@ -111,8 +119,7 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Filter не является прототипом filter'); } - var maxLevel = arguments[2] === undefined ? Infinity : arguments[2]; - var workWithFriends = choiceFriendsOnLevel(friends, maxLevel); + var workWithFriends = choiceFriendsOnLevel(friends, arguments[2], filter); this.inviteFriends = filterFriendsByGender(workWithFriends, filter); this.indexFriend = 0; } @@ -191,6 +198,7 @@ Filter.prototype.apply = function () { */ function MaleFilter() { this.field = allFilters.aMaleFilter; + this.type = 'male'; } MaleFilter.prototype = Object.create(Filter.prototype); @@ -202,6 +210,7 @@ MaleFilter.prototype = Object.create(Filter.prototype); */ function FemaleFilter() { this.field = allFilters.aFemaleFilter; + this.type = 'female'; } FemaleFilter.prototype = Object.create(Filter.prototype); From 196512d2daf2f04b55a75693bfa26df863fc84a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 15:54:08 +0500 Subject: [PATCH 19/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib.js b/lib.js index ac7447d..43f84d4 100644 --- a/lib.js +++ b/lib.js @@ -47,9 +47,8 @@ function choiceFriendsOnLevel(allFriends, maxLevel, filter) { if (filter.type === 'male') { return []; - } else { - maxLevel = Infinity; } + maxLevel = Infinity; } var friendsOnLevel = Object.create(levels); var sortFriends = []; From 1fc0e58669914d03e8b9f097532ac477909a22cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 16:46:38 +0500 Subject: [PATCH 20/40] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 162 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 86 insertions(+), 76 deletions(-) diff --git a/lib.js b/lib.js index 43f84d4..ae6bfcc 100644 --- a/lib.js +++ b/lib.js @@ -1,9 +1,26 @@ +Skip to content +This repository +Search +Pull requests +Issues +Gist + @Albina-G + Watch 0 + Star 0 + Fork 49 Albina-G/javascript-task-7 +forked from urfu-2016/javascript-task-7 + Code Pull requests 0 Projects 0 Pulse Graphs Settings +Tree: a1be98bd95 Find file Copy pathjavascript-task-7/lib.js +a1be98b 7 days ago +@Albina-G Albina-G синтаксис +1 contributor +RawBlameHistory +213 lines (178 sloc) 5.38 KB 'use strict'; var levels = { level: undefined, - friends: undefined, - names: undefined + friends: undefined }; function functionCompareByName(friend, friendNext) { @@ -11,100 +28,80 @@ function functionCompareByName(friend, friendNext) { return friend.name > friendNext.name ? 1 : -1; } -function onlyConnectedFriends(allFriends) { - var allFriendsFriends = []; - allFriends.forEach(function (item) { - item.friends.forEach(function (friendItem) { - allFriendsFriends.push(friendItem); - }); - }); - - return allFriendsFriends; -} - -function findBestFriends(arg, allFriends, noInviteFriends) { - var namesAllPeople = arg[0]; - var friendsOnLevel = arg[1]; - var friendsFriendsOnLevel = []; - friendsOnLevel.friends = allFriends.filter(function (item) { - if (item.best) { - choiceFriend(item, friendsFriendsOnLevel); +function choiceFriendsOnLevel(friends) { + var friendsBest = Object.create(levels); + var sortFriends = []; + var namesPeopleChoiceFriends = []; + var noInviteFriends = []; + var nameChoiceFriends = []; + friendsBest.level = 0; + friendsBest.friends = friends.filter(function (item) { + if (item.best !== undefined) { + choiceFriend(item, namesPeopleChoiceFriends); + nameChoiceFriends.push(item.name); return true; } - if (namesAllPeople.indexOf(item.name) !== -1) { - noInviteFriends.push(item); - } + noInviteFriends.push(item); return false; - }).sort(functionCompareByName); - friendsOnLevel.names = friendsFriendsOnLevel; -} - -function choiceFriendsOnLevel(allFriends, maxLevel, filter) { - if (maxLevel === undefined || maxLevel === 0) { - if (filter.type === 'male') { - - return []; - } - maxLevel = Infinity; - } - var friendsOnLevel = Object.create(levels); - var sortFriends = []; - var noInviteFriends = []; - friendsOnLevel.level = 0; - var namesAllPeople = onlyConnectedFriends(allFriends); - var argument1 = [namesAllPeople, friendsOnLevel]; - findBestFriends(argument1, allFriends, noInviteFriends); - sortFriends.push(friendsOnLevel); - var argument2 = [noInviteFriends, sortFriends]; - findFriends(argument2, maxLevel); + sortFriends.push(friendsBest); + var argument = [noInviteFriends, + namesPeopleChoiceFriends, + nameChoiceFriends + ]; + findFriends(argument, friends, sortFriends); return sortFriends; } -function findFriends(arg, maxLevel) { +function findFriends(arg, friends, sortFriends) { var noInviteFriends = arg[0]; - var sortFriends = arg[1]; + var namesPeopleChoiceFriends = arg[1]; + var nameChoiceFriends = arg[2]; var iteration = 1; - while (noInviteFriends.length !== 0) { - if (iteration === maxLevel) { - break; - } + while (nameChoiceFriends.length !== friends.length) { var friendsLevel = Object.create(levels); friendsLevel.level = iteration; var choiceFriends = []; - var argument = [noInviteFriends, sortFriends, friendsLevel]; - inspection(argument, iteration, choiceFriends); + var name = []; + var argument = [noInviteFriends, + namesPeopleChoiceFriends, + nameChoiceFriends, + choiceFriends, + name]; + inspection(argument); friendsLevel.friends = choiceFriends.sort(functionCompareByName); sortFriends.push(friendsLevel); iteration++; } } -function inspection(arg, iteration, choiceFriends) { +function inspection(arg) { var noInviteFriends = arg[0]; - var sortFriends = arg[1]; - var friendsLevel = arg[2]; - var namesFriends = []; + var namesPeopleChoiceFriends = arg[1]; + var nameChoiceFriends = arg[2]; + var choiceFriends = arg[3]; + var name = arg[4]; for (var i = 0; i < noInviteFriends.length; i++) { - var indexNamePeople = sortFriends[iteration - 1].names.indexOf(noInviteFriends[i].name); - if (indexNamePeople !== -1) { + var indexNamePeople = namesPeopleChoiceFriends.indexOf(noInviteFriends[i].name); + if (nameChoiceFriends.indexOf(noInviteFriends[i].name) === -1 && indexNamePeople !== -1) { choiceFriends.push(noInviteFriends[i]); - choiceFriend(noInviteFriends[i], namesFriends); - noInviteFriends.splice(i, 1); - i--; + nameChoiceFriends.push(noInviteFriends[i].name); + noInviteFriends[i].friends.forEach(function (nameFriendItem) { + name.push(nameFriendItem); + }); } } - friendsLevel.names = namesFriends; + name.forEach(function (item) { + namesPeopleChoiceFriends.push(item); + }); } -function choiceFriend(item, friendsFriendsOnLevel) { +function choiceFriend(item, namesPeopleChoiceFriends) { item.friends.forEach(function (nameFriendItem) { - if (friendsFriendsOnLevel.indexOf(item.name) === -1) { - friendsFriendsOnLevel.push(nameFriendItem); - } + namesPeopleChoiceFriends.push(nameFriendItem); }); } @@ -115,20 +112,25 @@ function choiceFriend(item, friendsFriendsOnLevel) { * @param {Filter} filter */ function Iterator(friends, filter) { + console.info(friends, filter); if (!(filter instanceof Filter)) { throw new TypeError('Filter не является прототипом filter'); } - var workWithFriends = choiceFriendsOnLevel(friends, arguments[2], filter); - this.inviteFriends = filterFriendsByGender(workWithFriends, filter); + this.inviteFriends = function () { + + return filterFriendsByGender(choiceFriendsOnLevel(friends), filter, Infinity); + }; this.indexFriend = 0; } -function filterFriendsByGender(friends, filter) { +function filterFriendsByGender(friends, filter, maxLevel) { var friendsFilter = []; friends.forEach(function (item) { item.friends.forEach(function (friend) { if (filter.field(friend)) { - friendsFilter.push(friend); + if (item.level < maxLevel) { + friendsFilter.push(friend); + } } }); }); @@ -138,7 +140,7 @@ function filterFriendsByGender(friends, filter) { Iterator.prototype.done = function () { - return this.indexFriend === this.inviteFriends.length; + return this.indexFriend === this.inviteFriends().length; }; Iterator.prototype.next = function () { @@ -148,7 +150,7 @@ Iterator.prototype.next = function () { } this.indexFriend++; - return this.inviteFriends[this.indexFriend - 1]; + return this.inviteFriends()[this.indexFriend - 1]; }; /** @@ -160,7 +162,12 @@ Iterator.prototype.next = function () { * @param {Number} maxLevel – максимальный круг друзей */ function LimitedIterator(friends, filter, maxLevel) { - Iterator.call(this, friends, filter, maxLevel); + console.info(friends, filter, maxLevel); + this.inviteFriends = function () { + + return filterFriendsByGender(choiceFriendsOnLevel(friends), filter, maxLevel); + }; + this.indexFriend = 0; } LimitedIterator.prototype = Object.create(Iterator.prototype); @@ -182,6 +189,7 @@ var allFilters = { * @constructor */ function Filter() { + console.info('Filter'); this.field = allFilters.aFilter; } @@ -196,8 +204,8 @@ Filter.prototype.apply = function () { * @constructor */ function MaleFilter() { + console.info('MaleFilter'); this.field = allFilters.aMaleFilter; - this.type = 'male'; } MaleFilter.prototype = Object.create(Filter.prototype); @@ -208,8 +216,8 @@ MaleFilter.prototype = Object.create(Filter.prototype); * @constructor */ function FemaleFilter() { + console.info('FemaleFilter'); this.field = allFilters.aFemaleFilter; - this.type = 'female'; } FemaleFilter.prototype = Object.create(Filter.prototype); @@ -220,3 +228,5 @@ exports.LimitedIterator = LimitedIterator; exports.Filter = Filter; exports.MaleFilter = MaleFilter; exports.FemaleFilter = FemaleFilter; +Contact GitHub API Training Shop Blog About +© 2016 GitHub, Inc. Terms Privacy Security Status Help From 15d4f9905c97623abfd7fe7faa746a8569e73af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 16:49:11 +0500 Subject: [PATCH 21/40] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/lib.js b/lib.js index ae6bfcc..26a0c17 100644 --- a/lib.js +++ b/lib.js @@ -1,21 +1,3 @@ -Skip to content -This repository -Search -Pull requests -Issues -Gist - @Albina-G - Watch 0 - Star 0 - Fork 49 Albina-G/javascript-task-7 -forked from urfu-2016/javascript-task-7 - Code Pull requests 0 Projects 0 Pulse Graphs Settings -Tree: a1be98bd95 Find file Copy pathjavascript-task-7/lib.js -a1be98b 7 days ago -@Albina-G Albina-G синтаксис -1 contributor -RawBlameHistory -213 lines (178 sloc) 5.38 KB 'use strict'; var levels = { @@ -219,14 +201,3 @@ function FemaleFilter() { console.info('FemaleFilter'); this.field = allFilters.aFemaleFilter; } - -FemaleFilter.prototype = Object.create(Filter.prototype); - -exports.Iterator = Iterator; -exports.LimitedIterator = LimitedIterator; - -exports.Filter = Filter; -exports.MaleFilter = MaleFilter; -exports.FemaleFilter = FemaleFilter; -Contact GitHub API Training Shop Blog About -© 2016 GitHub, Inc. Terms Privacy Security Status Help From c8852fe2ddcc6c4e4ea24f41532c4a3efe598fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 16:51:22 +0500 Subject: [PATCH 22/40] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib.js b/lib.js index 26a0c17..f365534 100644 --- a/lib.js +++ b/lib.js @@ -201,3 +201,12 @@ function FemaleFilter() { console.info('FemaleFilter'); this.field = allFilters.aFemaleFilter; } + +FemaleFilter.prototype = Object.create(Filter.prototype); + +exports.Iterator = Iterator; +exports.LimitedIterator = LimitedIterator; + +exports.Filter = Filter; +exports.MaleFilter = MaleFilter; +exports.FemaleFilter = FemaleFilter; From d495b404eb9a788f0b5353b6de38f0af6f8c1848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 20:57:33 +0500 Subject: [PATCH 23/40] =?UTF-8?q?=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB=D1=87=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 147 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 80 insertions(+), 67 deletions(-) diff --git a/lib.js b/lib.js index f365534..116dccd 100644 --- a/lib.js +++ b/lib.js @@ -2,7 +2,8 @@ var levels = { level: undefined, - friends: undefined + friends: undefined, + names: undefined }; function functionCompareByName(friend, friendNext) { @@ -10,80 +11,100 @@ function functionCompareByName(friend, friendNext) { return friend.name > friendNext.name ? 1 : -1; } -function choiceFriendsOnLevel(friends) { - var friendsBest = Object.create(levels); - var sortFriends = []; - var namesPeopleChoiceFriends = []; - var noInviteFriends = []; - var nameChoiceFriends = []; - friendsBest.level = 0; - friendsBest.friends = friends.filter(function (item) { - if (item.best !== undefined) { - choiceFriend(item, namesPeopleChoiceFriends); - nameChoiceFriends.push(item.name); +function onlyConnectedFriends(allFriends) { + var allFriendsFriends = []; + allFriends.forEach(function (item) { + item.friends.forEach(function (friendItem) { + allFriendsFriends.push(friendItem); + }); + }); + + return allFriendsFriends; +} + +function findBestFriends(arg, allFriends, noInviteFriends) { + var namesAllPeople = arg[0]; + var friendsOnLevel = arg[1]; + var friendsFriendsOnLevel = []; + friendsOnLevel.friends = allFriends.filter(function (item) { + if (item.best) { + choiceFriend(item, friendsFriendsOnLevel); return true; } - noInviteFriends.push(item); + if (namesAllPeople.indexOf(item.name) !== -1) { + noInviteFriends.push(item); + } return false; + }).sort(functionCompareByName); - sortFriends.push(friendsBest); - var argument = [noInviteFriends, - namesPeopleChoiceFriends, - nameChoiceFriends - ]; - findFriends(argument, friends, sortFriends); + friendsOnLevel.names = friendsFriendsOnLevel; +} + +function choiceFriendsOnLevel(allFriends, maxLevel, filter) { + if (maxLevel === undefined || maxLevel === 0) { + if (filter.type === 'male') { + + return []; + } + maxLevel = Infinity; + } + var friendsOnLevel = Object.create(levels); + var sortFriends = []; + var noInviteFriends = []; + friendsOnLevel.level = 0; + var namesAllPeople = onlyConnectedFriends(allFriends); + var argument1 = [namesAllPeople, friendsOnLevel]; + findBestFriends(argument1, allFriends, noInviteFriends); + sortFriends.push(friendsOnLevel); + var argument2 = [noInviteFriends, sortFriends]; + findFriends(argument2, maxLevel); return sortFriends; } -function findFriends(arg, friends, sortFriends) { +function findFriends(arg, maxLevel) { var noInviteFriends = arg[0]; - var namesPeopleChoiceFriends = arg[1]; - var nameChoiceFriends = arg[2]; + var sortFriends = arg[1]; var iteration = 1; - while (nameChoiceFriends.length !== friends.length) { + while (noInviteFriends.length !== 0) { + if (iteration === maxLevel) { + break; + } var friendsLevel = Object.create(levels); friendsLevel.level = iteration; var choiceFriends = []; - var name = []; - var argument = [noInviteFriends, - namesPeopleChoiceFriends, - nameChoiceFriends, - choiceFriends, - name]; - inspection(argument); + var argument = [noInviteFriends, sortFriends, friendsLevel]; + inspection(argument, iteration, choiceFriends); friendsLevel.friends = choiceFriends.sort(functionCompareByName); sortFriends.push(friendsLevel); iteration++; } } -function inspection(arg) { +function inspection(arg, iteration, choiceFriends) { var noInviteFriends = arg[0]; - var namesPeopleChoiceFriends = arg[1]; - var nameChoiceFriends = arg[2]; - var choiceFriends = arg[3]; - var name = arg[4]; + var sortFriends = arg[1]; + var friendsLevel = arg[2]; + var namesFriends = []; for (var i = 0; i < noInviteFriends.length; i++) { - var indexNamePeople = namesPeopleChoiceFriends.indexOf(noInviteFriends[i].name); - if (nameChoiceFriends.indexOf(noInviteFriends[i].name) === -1 && indexNamePeople !== -1) { + var indexNamePeople = sortFriends[iteration - 1].names.indexOf(noInviteFriends[i].name); + if (indexNamePeople !== -1) { choiceFriends.push(noInviteFriends[i]); - nameChoiceFriends.push(noInviteFriends[i].name); - noInviteFriends[i].friends.forEach(function (nameFriendItem) { - name.push(nameFriendItem); - }); + choiceFriend(noInviteFriends[i], namesFriends); + noInviteFriends.splice(i, 1); + i--; } } - name.forEach(function (item) { - namesPeopleChoiceFriends.push(item); - }); + friendsLevel.names = namesFriends; } -function choiceFriend(item, namesPeopleChoiceFriends) { +function choiceFriend(item, friendsFriendsOnLevel) { item.friends.forEach(function (nameFriendItem) { - namesPeopleChoiceFriends.push(nameFriendItem); + if (friendsFriendsOnLevel.indexOf(item.name) === -1) { + friendsFriendsOnLevel.push(nameFriendItem); + } }); } @@ -94,25 +115,20 @@ function choiceFriend(item, namesPeopleChoiceFriends) { * @param {Filter} filter */ function Iterator(friends, filter) { - console.info(friends, filter); if (!(filter instanceof Filter)) { throw new TypeError('Filter не является прототипом filter'); } - this.inviteFriends = function () { - - return filterFriendsByGender(choiceFriendsOnLevel(friends), filter, Infinity); - }; + var workWithFriends = choiceFriendsOnLevel(friends, arguments[2], filter); + this.inviteFriends = filterFriendsByGender(workWithFriends, filter); this.indexFriend = 0; } -function filterFriendsByGender(friends, filter, maxLevel) { +function filterFriendsByGender(friends, filter) { var friendsFilter = []; friends.forEach(function (item) { item.friends.forEach(function (friend) { if (filter.field(friend)) { - if (item.level < maxLevel) { - friendsFilter.push(friend); - } + friendsFilter.push(friend); } }); }); @@ -122,7 +138,7 @@ function filterFriendsByGender(friends, filter, maxLevel) { Iterator.prototype.done = function () { - return this.indexFriend === this.inviteFriends().length; + return this.indexFriend === this.inviteFriends.length; }; Iterator.prototype.next = function () { @@ -132,7 +148,7 @@ Iterator.prototype.next = function () { } this.indexFriend++; - return this.inviteFriends()[this.indexFriend - 1]; + return this.inviteFriends[this.indexFriend - 1]; }; /** @@ -144,18 +160,16 @@ Iterator.prototype.next = function () { * @param {Number} maxLevel – максимальный круг друзей */ function LimitedIterator(friends, filter, maxLevel) { - console.info(friends, filter, maxLevel); - this.inviteFriends = function () { - - return filterFriendsByGender(choiceFriendsOnLevel(friends), filter, maxLevel); - }; - this.indexFriend = 0; + Iterator.call(this, friends, filter, maxLevel); } LimitedIterator.prototype = Object.create(Iterator.prototype); var allFilters = { - aFilter: true, + aFilter: function () { + + return true; + }, aMaleFilter: function (friend) { return friend.gender === 'male'; @@ -171,7 +185,6 @@ var allFilters = { * @constructor */ function Filter() { - console.info('Filter'); this.field = allFilters.aFilter; } @@ -186,8 +199,8 @@ Filter.prototype.apply = function () { * @constructor */ function MaleFilter() { - console.info('MaleFilter'); this.field = allFilters.aMaleFilter; + this.type = 'male'; } MaleFilter.prototype = Object.create(Filter.prototype); @@ -198,8 +211,8 @@ MaleFilter.prototype = Object.create(Filter.prototype); * @constructor */ function FemaleFilter() { - console.info('FemaleFilter'); this.field = allFilters.aFemaleFilter; + this.type = 'female'; } FemaleFilter.prototype = Object.create(Filter.prototype); From 35b639061e9d0d8d66e07d851e8ba0047e687ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Wed, 30 Nov 2016 22:32:07 +0500 Subject: [PATCH 24/40] =?UTF-8?q?=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D0=BE=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.js b/lib.js index 116dccd..8082581 100644 --- a/lib.js +++ b/lib.js @@ -44,7 +44,7 @@ function findBestFriends(arg, allFriends, noInviteFriends) { function choiceFriendsOnLevel(allFriends, maxLevel, filter) { if (maxLevel === undefined || maxLevel === 0) { - if (filter.type === 'male') { + if (filter.type !== 'female') { return []; } From c4432b5ccb0453e9154af631d711b13fe7c5b070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Thu, 1 Dec 2016 21:35:58 +0500 Subject: [PATCH 25/40] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib.js b/lib.js index 8082581..5bdc038 100644 --- a/lib.js +++ b/lib.js @@ -11,10 +11,24 @@ function functionCompareByName(friend, friendNext) { return friend.name > friendNext.name ? 1 : -1; } +function checkTypeOfGraph(allFriends, friendItem, item) { + allFriends.forEach(function (friend) { + if (friend.name === friendItem) { + if (friend.friends!== [] && friend.friends.indexOf(item.name)) { + throw new TypeError('Ориентированный граф друзей'); + } + } + }); +} + function onlyConnectedFriends(allFriends) { var allFriendsFriends = []; allFriends.forEach(function (item) { + if (item.friends === undefined || item.friends.indexOf(undefined) !== -1) { + throw new TypeError('friends of ungefined'); + } item.friends.forEach(function (friendItem) { + checkTypeOfGraph(allFriends, friendItem, item); allFriendsFriends.push(friendItem); }); }); @@ -28,7 +42,9 @@ function findBestFriends(arg, allFriends, noInviteFriends) { var friendsFriendsOnLevel = []; friendsOnLevel.friends = allFriends.filter(function (item) { if (item.best) { + console.info(item.name); choiceFriend(item, friendsFriendsOnLevel); + console.info(friendsFriendsOnLevel); return true; } From cd5c5a356c9c4f2024fb42967857e432c1848256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Thu, 1 Dec 2016 21:48:37 +0500 Subject: [PATCH 26/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib.js b/lib.js index 5bdc038..a990b5f 100644 --- a/lib.js +++ b/lib.js @@ -14,7 +14,7 @@ function functionCompareByName(friend, friendNext) { function checkTypeOfGraph(allFriends, friendItem, item) { allFriends.forEach(function (friend) { if (friend.name === friendItem) { - if (friend.friends!== [] && friend.friends.indexOf(item.name)) { + if (friend.friends !== [] && friend.friends.indexOf(item.name) === -1) { throw new TypeError('Ориентированный граф друзей'); } } @@ -42,9 +42,7 @@ function findBestFriends(arg, allFriends, noInviteFriends) { var friendsFriendsOnLevel = []; friendsOnLevel.friends = allFriends.filter(function (item) { if (item.best) { - console.info(item.name); choiceFriend(item, friendsFriendsOnLevel); - console.info(friendsFriendsOnLevel); return true; } From 149314dd21b56243e2e66c1655ef4875b06e05c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Thu, 1 Dec 2016 21:53:57 +0500 Subject: [PATCH 27/40] =?UTF-8?q?=D0=B1=D0=B5=D0=B7=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=BE=D1=80=D0=B8=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib.js b/lib.js index a990b5f..9e5a983 100644 --- a/lib.js +++ b/lib.js @@ -11,16 +11,6 @@ function functionCompareByName(friend, friendNext) { return friend.name > friendNext.name ? 1 : -1; } -function checkTypeOfGraph(allFriends, friendItem, item) { - allFriends.forEach(function (friend) { - if (friend.name === friendItem) { - if (friend.friends !== [] && friend.friends.indexOf(item.name) === -1) { - throw new TypeError('Ориентированный граф друзей'); - } - } - }); -} - function onlyConnectedFriends(allFriends) { var allFriendsFriends = []; allFriends.forEach(function (item) { @@ -28,7 +18,6 @@ function onlyConnectedFriends(allFriends) { throw new TypeError('friends of ungefined'); } item.friends.forEach(function (friendItem) { - checkTypeOfGraph(allFriends, friendItem, item); allFriendsFriends.push(friendItem); }); }); From 3c992563c652d0ba6af2c31d65ad286e26d8698e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Fri, 2 Dec 2016 22:05:06 +0500 Subject: [PATCH 28/40] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BE=D1=80=D0=B8=D0=B5=D0=BD=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lib.js b/lib.js index 9e5a983..9f2232a 100644 --- a/lib.js +++ b/lib.js @@ -3,7 +3,8 @@ var levels = { level: undefined, friends: undefined, - names: undefined + names: undefined, + namesLevel: undefined }; function functionCompareByName(friend, friendNext) { @@ -29,9 +30,10 @@ function findBestFriends(arg, allFriends, noInviteFriends) { var namesAllPeople = arg[0]; var friendsOnLevel = arg[1]; var friendsFriendsOnLevel = []; + var namesFriendsOnLevel = []; friendsOnLevel.friends = allFriends.filter(function (item) { if (item.best) { - choiceFriend(item, friendsFriendsOnLevel); + choiceFriend(item, friendsFriendsOnLevel, namesFriendsOnLevel); return true; } @@ -43,6 +45,7 @@ function findBestFriends(arg, allFriends, noInviteFriends) { }).sort(functionCompareByName); friendsOnLevel.names = friendsFriendsOnLevel; + friendsOnLevel.namesLevel = namesFriendsOnLevel; } function choiceFriendsOnLevel(allFriends, maxLevel, filter) { @@ -91,19 +94,35 @@ function inspection(arg, iteration, choiceFriends) { var sortFriends = arg[1]; var friendsLevel = arg[2]; var namesFriends = []; + var namesOnLevel = []; for (var i = 0; i < noInviteFriends.length; i++) { var indexNamePeople = sortFriends[iteration - 1].names.indexOf(noInviteFriends[i].name); if (indexNamePeople !== -1) { + checkTypeGraph(sortFriends, noInviteFriends[i], iteration); choiceFriends.push(noInviteFriends[i]); - choiceFriend(noInviteFriends[i], namesFriends); + choiceFriend(noInviteFriends[i], namesFriends, namesOnLevel); noInviteFriends.splice(i, 1); i--; } } friendsLevel.names = namesFriends; + friendsLevel.namesLevel = namesOnLevel; } -function choiceFriend(item, friendsFriendsOnLevel) { +function checkTypeGraph(sortFriends, item, iteration) { + var index = 0; + item.friends.forEach(function (friend) { + if (sortFriends[iteration-1].namesLevel.indexOf(friend) !== -1) { + index++; + } + }); + if (index === 0) { + throw new TypeError('Граф ориентированный'); + } +} + +function choiceFriend(item, friendsFriendsOnLevel, namesFriendsOnLevel) { + namesFriendsOnLevel.push(item.name); item.friends.forEach(function (nameFriendItem) { if (friendsFriendsOnLevel.indexOf(item.name) === -1) { friendsFriendsOnLevel.push(nameFriendItem); @@ -189,6 +208,7 @@ var allFilters = { */ function Filter() { this.field = allFilters.aFilter; + this.type = 'filter'; } Filter.prototype.apply = function () { From f15483e4318661abc562f5bde69f2d2b6f0d8ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Fri, 2 Dec 2016 22:07:43 +0500 Subject: [PATCH 29/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.js b/lib.js index 9f2232a..0af70e1 100644 --- a/lib.js +++ b/lib.js @@ -112,7 +112,7 @@ function inspection(arg, iteration, choiceFriends) { function checkTypeGraph(sortFriends, item, iteration) { var index = 0; item.friends.forEach(function (friend) { - if (sortFriends[iteration-1].namesLevel.indexOf(friend) !== -1) { + if (sortFriends[iteration - 1].namesLevel.indexOf(friend) !== -1) { index++; } }); From 02681f53bf2035437faf3573efc7ad805ecb13f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Fri, 2 Dec 2016 22:32:58 +0500 Subject: [PATCH 30/40] =?UTF-8?q?=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=80=D0=B8=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.js b/lib.js index 0af70e1..5a2e85d 100644 --- a/lib.js +++ b/lib.js @@ -116,7 +116,7 @@ function checkTypeGraph(sortFriends, item, iteration) { index++; } }); - if (index === 0) { + if (index === 0 && item.friends.length !== 0) { throw new TypeError('Граф ориентированный'); } } From 16bc352594cdea25e504399ebda7eff0daa689f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Fri, 2 Dec 2016 23:12:54 +0500 Subject: [PATCH 31/40] =?UTF-8?q?=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20?= =?UTF-8?q?=D0=B4=D1=80=D1=83=D0=B7=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/lib.js b/lib.js index 5a2e85d..5137ef9 100644 --- a/lib.js +++ b/lib.js @@ -15,7 +15,7 @@ function functionCompareByName(friend, friendNext) { function onlyConnectedFriends(allFriends) { var allFriendsFriends = []; allFriends.forEach(function (item) { - if (item.friends === undefined || item.friends.indexOf(undefined) !== -1) { + if (item.friends === undefined) { throw new TypeError('friends of ungefined'); } item.friends.forEach(function (friendItem) { @@ -98,7 +98,6 @@ function inspection(arg, iteration, choiceFriends) { for (var i = 0; i < noInviteFriends.length; i++) { var indexNamePeople = sortFriends[iteration - 1].names.indexOf(noInviteFriends[i].name); if (indexNamePeople !== -1) { - checkTypeGraph(sortFriends, noInviteFriends[i], iteration); choiceFriends.push(noInviteFriends[i]); choiceFriend(noInviteFriends[i], namesFriends, namesOnLevel); noInviteFriends.splice(i, 1); @@ -109,18 +108,6 @@ function inspection(arg, iteration, choiceFriends) { friendsLevel.namesLevel = namesOnLevel; } -function checkTypeGraph(sortFriends, item, iteration) { - var index = 0; - item.friends.forEach(function (friend) { - if (sortFriends[iteration - 1].namesLevel.indexOf(friend) !== -1) { - index++; - } - }); - if (index === 0 && item.friends.length !== 0) { - throw new TypeError('Граф ориентированный'); - } -} - function choiceFriend(item, friendsFriendsOnLevel, namesFriendsOnLevel) { namesFriendsOnLevel.push(item.name); item.friends.forEach(function (nameFriendItem) { From 6f9ee5499c1b5ae4542b1911a140266df0e5a94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Fri, 2 Dec 2016 23:20:35 +0500 Subject: [PATCH 32/40] =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=D1=82,=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20undefined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib.js b/lib.js index 5137ef9..d4e4cf8 100644 --- a/lib.js +++ b/lib.js @@ -3,8 +3,7 @@ var levels = { level: undefined, friends: undefined, - names: undefined, - namesLevel: undefined + names: undefined }; function functionCompareByName(friend, friendNext) { @@ -30,10 +29,9 @@ function findBestFriends(arg, allFriends, noInviteFriends) { var namesAllPeople = arg[0]; var friendsOnLevel = arg[1]; var friendsFriendsOnLevel = []; - var namesFriendsOnLevel = []; friendsOnLevel.friends = allFriends.filter(function (item) { if (item.best) { - choiceFriend(item, friendsFriendsOnLevel, namesFriendsOnLevel); + choiceFriend(item, friendsFriendsOnLevel); return true; } @@ -45,7 +43,6 @@ function findBestFriends(arg, allFriends, noInviteFriends) { }).sort(functionCompareByName); friendsOnLevel.names = friendsFriendsOnLevel; - friendsOnLevel.namesLevel = namesFriendsOnLevel; } function choiceFriendsOnLevel(allFriends, maxLevel, filter) { @@ -94,22 +91,19 @@ function inspection(arg, iteration, choiceFriends) { var sortFriends = arg[1]; var friendsLevel = arg[2]; var namesFriends = []; - var namesOnLevel = []; for (var i = 0; i < noInviteFriends.length; i++) { var indexNamePeople = sortFriends[iteration - 1].names.indexOf(noInviteFriends[i].name); if (indexNamePeople !== -1) { choiceFriends.push(noInviteFriends[i]); - choiceFriend(noInviteFriends[i], namesFriends, namesOnLevel); + choiceFriend(noInviteFriends[i], namesFriends); noInviteFriends.splice(i, 1); i--; } } friendsLevel.names = namesFriends; - friendsLevel.namesLevel = namesOnLevel; } -function choiceFriend(item, friendsFriendsOnLevel, namesFriendsOnLevel) { - namesFriendsOnLevel.push(item.name); +function choiceFriend(item, friendsFriendsOnLevel) { item.friends.forEach(function (nameFriendItem) { if (friendsFriendsOnLevel.indexOf(item.name) === -1) { friendsFriendsOnLevel.push(nameFriendItem); @@ -195,7 +189,6 @@ var allFilters = { */ function Filter() { this.field = allFilters.aFilter; - this.type = 'filter'; } Filter.prototype.apply = function () { From cfee52088690002e981ff7c38715858a0815aa25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Fri, 2 Dec 2016 23:44:37 +0500 Subject: [PATCH 33/40] =?UTF-8?q?=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib.js b/lib.js index d4e4cf8..413f997 100644 --- a/lib.js +++ b/lib.js @@ -189,6 +189,7 @@ var allFilters = { */ function Filter() { this.field = allFilters.aFilter; + this.type = 'filter'; } Filter.prototype.apply = function () { From 9822b15d719fd1b8e036f497f9482cc8cb287057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Fri, 2 Dec 2016 23:50:43 +0500 Subject: [PATCH 34/40] xnj --- lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.js b/lib.js index 413f997..d8328df 100644 --- a/lib.js +++ b/lib.js @@ -14,7 +14,7 @@ function functionCompareByName(friend, friendNext) { function onlyConnectedFriends(allFriends) { var allFriendsFriends = []; allFriends.forEach(function (item) { - if (item.friends === undefined) { + if (item.friends === undefined || item.friends.indexOf(undefined) !== -1) { throw new TypeError('friends of ungefined'); } item.friends.forEach(function (friendItem) { From f8bbcdec5481b0559b8a07b48f3b1f775ddb221c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 3 Dec 2016 00:14:33 +0500 Subject: [PATCH 35/40] filter --- lib.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib.js b/lib.js index d8328df..9e5a983 100644 --- a/lib.js +++ b/lib.js @@ -189,7 +189,6 @@ var allFilters = { */ function Filter() { this.field = allFilters.aFilter; - this.type = 'filter'; } Filter.prototype.apply = function () { From 2abd0f88eb6e673a67077f156bb0a82344c62d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 3 Dec 2016 00:23:39 +0500 Subject: [PATCH 36/40] =?UTF-8?q?=D0=B8=D1=82=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib.js b/lib.js index 9e5a983..ae93a0e 100644 --- a/lib.js +++ b/lib.js @@ -45,14 +45,7 @@ function findBestFriends(arg, allFriends, noInviteFriends) { friendsOnLevel.names = friendsFriendsOnLevel; } -function choiceFriendsOnLevel(allFriends, maxLevel, filter) { - if (maxLevel === undefined || maxLevel === 0) { - if (filter.type !== 'female') { - - return []; - } - maxLevel = Infinity; - } +function choiceFriendsOnLevel(allFriends, maxLevel) { var friendsOnLevel = Object.create(levels); var sortFriends = []; var noInviteFriends = []; @@ -121,8 +114,15 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Filter не является прототипом filter'); } - var workWithFriends = choiceFriendsOnLevel(friends, arguments[2], filter); - this.inviteFriends = filterFriendsByGender(workWithFriends, filter); + var maxLevel = arguments[2] === undefined ? Infinity : arguments[2]; + var workWithFriends = function () { + if (maxLevel === 0) { + return []; + } + + return choiceFriendsOnLevel(friends, maxLevel); + } + this.inviteFriends = filterFriendsByGender(workWithFriends(), filter); this.indexFriend = 0; } @@ -163,6 +163,7 @@ Iterator.prototype.next = function () { * @param {Number} maxLevel – максимальный круг друзей */ function LimitedIterator(friends, filter, maxLevel) { + maxLevel = maxLevel === undefined ? 0 : maxLevel; Iterator.call(this, friends, filter, maxLevel); } @@ -203,7 +204,6 @@ Filter.prototype.apply = function () { */ function MaleFilter() { this.field = allFilters.aMaleFilter; - this.type = 'male'; } MaleFilter.prototype = Object.create(Filter.prototype); @@ -215,7 +215,6 @@ MaleFilter.prototype = Object.create(Filter.prototype); */ function FemaleFilter() { this.field = allFilters.aFemaleFilter; - this.type = 'female'; } FemaleFilter.prototype = Object.create(Filter.prototype); From f6b248f644d3eef757ed64551488359e0fcef1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 3 Dec 2016 00:29:58 +0500 Subject: [PATCH 37/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib.js b/lib.js index ae93a0e..545ee2c 100644 --- a/lib.js +++ b/lib.js @@ -115,14 +115,11 @@ function Iterator(friends, filter) { throw new TypeError('Filter не является прототипом filter'); } var maxLevel = arguments[2] === undefined ? Infinity : arguments[2]; - var workWithFriends = function () { - if (maxLevel === 0) { - return []; - } - - return choiceFriendsOnLevel(friends, maxLevel); + var workWithFriends = []; + if (maxLevel !== 0) { + workWithFriends = choiceFriendsOnLevel(friends, maxLevel); } - this.inviteFriends = filterFriendsByGender(workWithFriends(), filter); + this.inviteFriends = filterFriendsByGender(workWithFriends, filter); this.indexFriend = 0; } From f743663ae8c0c2473dd269c3200416bbf55e3c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 3 Dec 2016 01:10:04 +0500 Subject: [PATCH 38/40] =?UTF-8?q?=D1=83=D1=81=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=88=D0=B5=D0=BD=D1=81=D1=82=D0=B2=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D1=82=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib.js b/lib.js index 545ee2c..a69546b 100644 --- a/lib.js +++ b/lib.js @@ -45,7 +45,15 @@ function findBestFriends(arg, allFriends, noInviteFriends) { friendsOnLevel.names = friendsFriendsOnLevel; } -function choiceFriendsOnLevel(allFriends, maxLevel) { +function choiceFriendsOnLevel(allFriends, maxLevel, filter) { + if (filter.type !== 'male') { + maxLevel = Infinity; + } else { + if (maxLevel === undefined || maxLevel === 0) { + + return []; + } + } var friendsOnLevel = Object.create(levels); var sortFriends = []; var noInviteFriends = []; @@ -114,11 +122,7 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Filter не является прототипом filter'); } - var maxLevel = arguments[2] === undefined ? Infinity : arguments[2]; - var workWithFriends = []; - if (maxLevel !== 0) { - workWithFriends = choiceFriendsOnLevel(friends, maxLevel); - } + var workWithFriends = choiceFriendsOnLevel(friends, arguments[2], filter); this.inviteFriends = filterFriendsByGender(workWithFriends, filter); this.indexFriend = 0; } @@ -160,7 +164,6 @@ Iterator.prototype.next = function () { * @param {Number} maxLevel – максимальный круг друзей */ function LimitedIterator(friends, filter, maxLevel) { - maxLevel = maxLevel === undefined ? 0 : maxLevel; Iterator.call(this, friends, filter, maxLevel); } @@ -201,6 +204,7 @@ Filter.prototype.apply = function () { */ function MaleFilter() { this.field = allFilters.aMaleFilter; + this.type = 'male'; } MaleFilter.prototype = Object.create(Filter.prototype); From f420a84cf064332f031cf9f35bffd080f808dd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 3 Dec 2016 01:15:46 +0500 Subject: [PATCH 39/40] =?UTF-8?q?=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib.js b/lib.js index a69546b..ba39298 100644 --- a/lib.js +++ b/lib.js @@ -48,11 +48,10 @@ function findBestFriends(arg, allFriends, noInviteFriends) { function choiceFriendsOnLevel(allFriends, maxLevel, filter) { if (filter.type !== 'male') { maxLevel = Infinity; - } else { - if (maxLevel === undefined || maxLevel === 0) { + } + if (maxLevel === undefined || maxLevel === 0) { - return []; - } + return []; } var friendsOnLevel = Object.create(levels); var sortFriends = []; From fddbcd7169a2e9b352d3929469b67d3197e50b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BD=D0=B8=D0=B5=D0=B2=D0=B0=20=D0=90=D0=BB?= =?UTF-8?q?=D1=8C=D0=B1=D0=B8=D0=BD=D0=B0=20=D0=9D=D0=B0=D0=B6=D0=B8=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=B0?= Date: Sat, 3 Dec 2016 01:24:59 +0500 Subject: [PATCH 40/40] =?UTF-8?q?=D0=B8=D1=82=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib.js b/lib.js index ba39298..b061ec3 100644 --- a/lib.js +++ b/lib.js @@ -215,6 +215,7 @@ MaleFilter.prototype = Object.create(Filter.prototype); */ function FemaleFilter() { this.field = allFilters.aFemaleFilter; + this.type = 'female'; } FemaleFilter.prototype = Object.create(Filter.prototype);