From bbfb41cf24811836618c9e2195e1a4bafed34606 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Tue, 22 Nov 2016 14:15:14 +0500 Subject: [PATCH 01/34] =?UTF-8?q?=D0=9F=D0=BE=D0=BA=D0=B0=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=BE=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B8=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D1=82=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 106 insertions(+), 5 deletions(-) diff --git a/lib.js b/lib.js index 60f30ab..09db44c 100644 --- a/lib.js +++ b/lib.js @@ -6,9 +6,76 @@ * @param {Object[]} friends * @param {Filter} filter */ +var listAllPersons; +var usedFriendNames; +var countCircles; + +function compareAlphabetically(person1, person2) { + if (person1.name > person2.name) { + return 1; + } + if (person1.name < person2.name) { + return -1; + } + + return 0; +} + +function foundFirstCircle() { + countCircles++; + + return listAllPersons.filter(function (person) { + return person.best === true; + }).sort(compareAlphabetically); +} + +function foundNextCircle(currentListFriends) { + countCircles++; + var namesFriends = []; + currentListFriends.forEach(function (person) { + namesFriends = namesFriends.concat(person.friends); + }); + + return listAllPersons.filter(function (person) { + var usedName = usedFriendNames.indexOf(person.name) !== -1; + if (namesFriends.indexOf(person.name) !== -1 && !usedName) { + usedFriendNames.push(person.name); + } + + return (namesFriends.indexOf(person.name) !== -1 && !usedName); + }).sort(compareAlphabetically); +} + function Iterator(friends, filter) { - console.info(friends, filter); + countCircles = 0; + usedFriendNames = []; + listAllPersons = friends; + if (!(filter instanceof Filter)) { + throw new TypeError('Incorrect data type Filter'); + } + var listBestFriends = [].concat(foundFirstCircle()); + usedFriendNames = listBestFriends.map(function (person) { + return person.name; + }); + this.listGuests = [].concat(listBestFriends); + var currentListFriends = foundNextCircle(listBestFriends); + this.listGuests = this.listGuests.concat(currentListFriends); + + while (usedFriendNames.length !== friends.length) { + currentListFriends = foundNextCircle(currentListFriends); + this.listGuests = this.listGuests.concat(currentListFriends); + } + this.listGuests = this.listGuests.filter(function (friend) { + return filter.filterFriends(friend); + }); + this.listGuests.reverse(); } +Iterator.prototype.done = function () { + return this.listGuests.length === 0; +}; +Iterator.prototype.next = function () { + return this.listGuests.pop(); +}; /** * Итератор по друзям с ограничением по кругу @@ -19,15 +86,41 @@ function Iterator(friends, filter) { * @param {Number} maxLevel – максимальный круг друзей */ function LimitedIterator(friends, filter, maxLevel) { - console.info(friends, filter, maxLevel); + countCircles = 0; + usedFriendNames = []; + listAllPersons = friends; + if (!(filter instanceof Filter)) { + throw new TypeError('Incorrect data type Filter'); + } + var listBestFriends = [].concat(foundFirstCircle()); + usedFriendNames = listBestFriends.map(function (person) { + return person.name; + }); + this.listGuests = [].concat(listBestFriends); + var currentListFriends = foundNextCircle(listBestFriends); + this.listGuests = this.listGuests.concat(currentListFriends); + + while (countCircles !== maxLevel) { + currentListFriends = foundNextCircle(currentListFriends); + this.listGuests = this.listGuests.concat(currentListFriends); + } + this.listGuests = this.listGuests.filter(function (friend) { + return filter.filterFriends(friend); + }); + this.listGuests.reverse(); } +LimitedIterator.prototype = Object.create(Iterator.prototype); +LimitedIterator.prototype.constructor = LimitedIterator; + /** * Фильтр друзей * @constructor */ function Filter() { - console.info('Filter'); + this.filter = function () { + return true; + }; } /** @@ -36,8 +129,12 @@ function Filter() { * @constructor */ function MaleFilter() { - console.info('MaleFilter'); + this.filterFriends = function (friend) { + return friend.gender === 'male'; + }; } +MaleFilter.prototype = Object.create(Filter.prototype); +MaleFilter.prototype.constructor = MaleFilter; /** * Фильтр друзей-девушек @@ -45,8 +142,12 @@ function MaleFilter() { * @constructor */ function FemaleFilter() { - console.info('FemaleFilter'); + this.filterFriends = function (friend) { + return friend.gender === 'female'; + }; } +FemaleFilter.prototype = Object.create(Filter.prototype); +FemaleFilter.prototype.constructor = FemaleFilter; exports.Iterator = Iterator; exports.LimitedIterator = LimitedIterator; From 568484ea0558a54727207ed152585f53e5b10ace Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Tue, 22 Nov 2016 16:27:31 +0500 Subject: [PATCH 02/34] =?UTF-8?q?=D0=9F=D0=BE=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=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 | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/lib.js b/lib.js index 09db44c..e46b50b 100644 --- a/lib.js +++ b/lib.js @@ -33,7 +33,11 @@ function foundNextCircle(currentListFriends) { countCircles++; var namesFriends = []; currentListFriends.forEach(function (person) { - namesFriends = namesFriends.concat(person.friends); + for (var i = 0; i < person.friends.length; i++) { + if (namesFriends.indexOf(person.friends[i]) === -1) { + namesFriends.push(person.friends[i]); + } + } }); return listAllPersons.filter(function (person) { @@ -46,25 +50,40 @@ function foundNextCircle(currentListFriends) { }).sort(compareAlphabetically); } -function Iterator(friends, filter) { - countCircles = 0; - usedFriendNames = []; - listAllPersons = friends; - if (!(filter instanceof Filter)) { - throw new TypeError('Incorrect data type Filter'); - } +function foundIncoherentFriends() { + return listAllPersons.filter(function (person) { + return usedFriendNames.indexOf(person.name) === -1; + }).sort(compareAlphabetically); +} + +function getListGuest() { var listBestFriends = [].concat(foundFirstCircle()); usedFriendNames = listBestFriends.map(function (person) { return person.name; }); - this.listGuests = [].concat(listBestFriends); + var listGuests = [].concat(listBestFriends); var currentListFriends = foundNextCircle(listBestFriends); - this.listGuests = this.listGuests.concat(currentListFriends); + listGuests = listGuests.concat(currentListFriends); - while (usedFriendNames.length !== friends.length) { + while (currentListFriends.length !== 0) { currentListFriends = foundNextCircle(currentListFriends); - this.listGuests = this.listGuests.concat(currentListFriends); + listGuests = listGuests.concat(currentListFriends); } + if (usedFriendNames.length !== listAllPersons.length) { + currentListFriends = foundIncoherentFriends(); + listGuests = listGuests.concat(currentListFriends); + } + + return listGuests; +} + +function Iterator(friends, filter) { + usedFriendNames = []; + listAllPersons = friends; + if (!(filter instanceof Filter)) { + throw new TypeError('Incorrect data type Filter'); + } + this.listGuests = getListGuest(); this.listGuests = this.listGuests.filter(function (friend) { return filter.filterFriends(friend); }); @@ -85,6 +104,7 @@ Iterator.prototype.next = function () { * @param {Filter} filter * @param {Number} maxLevel – максимальный круг друзей */ + function LimitedIterator(friends, filter, maxLevel) { countCircles = 0; usedFriendNames = []; From e95e76135c5f21715488908d2e4b6af363fc633a Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Tue, 22 Nov 2016 21:43:39 +0500 Subject: [PATCH 03/34] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=8B=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=D0=B9=D1=82=D0=B8=20=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=BA=D0=BB=D0=B8=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 | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/lib.js b/lib.js index e46b50b..972939c 100644 --- a/lib.js +++ b/lib.js @@ -105,6 +105,24 @@ Iterator.prototype.next = function () { * @param {Number} maxLevel – максимальный круг друзей */ +function getListLimitGuest(maxLevel) { + var listBestFriends = [].concat(foundFirstCircle()); + usedFriendNames = listBestFriends.map(function (person) { + return person.name; + }); + var listGuests = [].concat(listBestFriends); + if (maxLevel > 1) { + var currentListFriends = foundNextCircle(listBestFriends); + listGuests = listGuests.concat(currentListFriends); + while (countCircles < maxLevel) { + currentListFriends = foundNextCircle(currentListFriends); + listGuests = listGuests.concat(currentListFriends); + } + } + + return listGuests; +} + function LimitedIterator(friends, filter, maxLevel) { countCircles = 0; usedFriendNames = []; @@ -112,22 +130,15 @@ function LimitedIterator(friends, filter, maxLevel) { if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } - var listBestFriends = [].concat(foundFirstCircle()); - usedFriendNames = listBestFriends.map(function (person) { - return person.name; - }); - this.listGuests = [].concat(listBestFriends); - var currentListFriends = foundNextCircle(listBestFriends); - this.listGuests = this.listGuests.concat(currentListFriends); - - while (countCircles !== maxLevel) { - currentListFriends = foundNextCircle(currentListFriends); - this.listGuests = this.listGuests.concat(currentListFriends); + if (maxLevel <= 0) { + this.listGuests = []; + } else { + this.listGuests = getListLimitGuest(maxLevel); + this.listGuests = this.listGuests.filter(function (friend) { + return filter.filterFriends(friend); + }); + this.listGuests.reverse(); } - this.listGuests = this.listGuests.filter(function (friend) { - return filter.filterFriends(friend); - }); - this.listGuests.reverse(); } LimitedIterator.prototype = Object.create(Iterator.prototype); From 207fadaf0fc53705cb4e8804939334f616d14151 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Tue, 22 Nov 2016 23:09:57 +0500 Subject: [PATCH 04/34] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B0=20null=20=D0=B8=20undefined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib.js b/lib.js index 972939c..d0b01f3 100644 --- a/lib.js +++ b/lib.js @@ -93,7 +93,7 @@ Iterator.prototype.done = function () { return this.listGuests.length === 0; }; Iterator.prototype.next = function () { - return this.listGuests.pop(); + return this.done() ? null : this.listGuests.pop(); }; /** @@ -124,6 +124,7 @@ function getListLimitGuest(maxLevel) { } function LimitedIterator(friends, filter, maxLevel) { + maxLevel = maxLevel === undefined ? 0 : maxLevel; countCircles = 0; usedFriendNames = []; listAllPersons = friends; From e69bdf472db11ddd6eeaddb021e4c0149b4a06f5 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Tue, 22 Nov 2016 23:50:11 +0500 Subject: [PATCH 05/34] =?UTF-8?q?=D0=92=D0=B4=D1=80=D1=83=D0=B3=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D0=B0=20=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BF=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=BD=D0=BE=D0=B9=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=D0=B5=D0=BA=D1=86=D0=B8=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 d0b01f3..3a78023 100644 --- a/lib.js +++ b/lib.js @@ -79,7 +79,7 @@ function getListGuest() { function Iterator(friends, filter) { usedFriendNames = []; - listAllPersons = friends; + listAllPersons = friends.slice(); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } From 9ca2ed97d2c97ec0b94047fec1627ff96bd6a472 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 00:42:10 +0500 Subject: [PATCH 06/34] =?UTF-8?q?=D0=A1=D0=BB=D1=83=D1=87=D0=B0=D0=B9,=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=B3=D0=B4=D0=B0=20=D0=BD=D0=B5=D1=82=20=D0=BB?= =?UTF-8?q?=D1=83=D1=87=D1=88=D0=B8=D1=85=20=D0=B4=D1=80=D1=83=D0=B7=D0=B5?= =?UTF-8?q?=D0=B9?= 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 3a78023..41f3dfc 100644 --- a/lib.js +++ b/lib.js @@ -69,7 +69,7 @@ function getListGuest() { currentListFriends = foundNextCircle(currentListFriends); listGuests = listGuests.concat(currentListFriends); } - if (usedFriendNames.length !== listAllPersons.length) { + if (usedFriendNames.length !== listAllPersons.length && listGuests.length !== 0) { currentListFriends = foundIncoherentFriends(); listGuests = listGuests.concat(currentListFriends); } From 23e50e64e0d81cc421240d1993b23df58d3153ff Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 01:17:38 +0500 Subject: [PATCH 07/34] =?UTF-8?q?=D0=95=D1=81=D0=BB=D0=B8=20=D0=BD=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BA=D0=B0=D0=BA=D0=BE=D0=B3=D0=BE-=D0=BD=D0=B8?= =?UTF-8?q?=D0=B1=D1=83=D0=B4=D1=8C=20=D1=83=D1=80=D0=BE=D0=B2=D0=BD=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib.js b/lib.js index 41f3dfc..f61fa14 100644 --- a/lib.js +++ b/lib.js @@ -9,6 +9,7 @@ var listAllPersons; var usedFriendNames; var countCircles; +var hasCircle; function compareAlphabetically(person1, person2) { if (person1.name > person2.name) { @@ -40,7 +41,7 @@ function foundNextCircle(currentListFriends) { } }); - return listAllPersons.filter(function (person) { + var ansList = listAllPersons.filter(function (person) { var usedName = usedFriendNames.indexOf(person.name) !== -1; if (namesFriends.indexOf(person.name) !== -1 && !usedName) { usedFriendNames.push(person.name); @@ -48,6 +49,11 @@ function foundNextCircle(currentListFriends) { return (namesFriends.indexOf(person.name) !== -1 && !usedName); }).sort(compareAlphabetically); + if (ansList.length === 0) { + hasCircle = false; + } + + return ansList; } function foundIncoherentFriends() { @@ -57,6 +63,7 @@ function foundIncoherentFriends() { } function getListGuest() { + hasCircle = true; var listBestFriends = [].concat(foundFirstCircle()); usedFriendNames = listBestFriends.map(function (person) { return person.name; @@ -64,8 +71,11 @@ function getListGuest() { var listGuests = [].concat(listBestFriends); var currentListFriends = foundNextCircle(listBestFriends); listGuests = listGuests.concat(currentListFriends); + if (listGuests.length === 0) { + hasCircle = false; + } - while (currentListFriends.length !== 0) { + while (currentListFriends.length !== 0 && hasCircle) { currentListFriends = foundNextCircle(currentListFriends); listGuests = listGuests.concat(currentListFriends); } From 0292aedcffd95a5177ff939f2a7ce2204c1d23f7 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 01:23:21 +0500 Subject: [PATCH 08/34] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B1=D0=B5=D0=B3=20=D0=BF=D0=BE=20=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=B2=D1=8F=D0=B7=D0=BD=D1=8B=D0=BC=20=D0=B4=D1=80?= =?UTF-8?q?=D1=83=D0=B7=D1=8C=D1=8F=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib.js b/lib.js index f61fa14..198b8cd 100644 --- a/lib.js +++ b/lib.js @@ -56,11 +56,11 @@ function foundNextCircle(currentListFriends) { return ansList; } -function foundIncoherentFriends() { +/* function foundIncoherentFriends() { return listAllPersons.filter(function (person) { return usedFriendNames.indexOf(person.name) === -1; }).sort(compareAlphabetically); -} +}*/ function getListGuest() { hasCircle = true; @@ -79,10 +79,10 @@ function getListGuest() { currentListFriends = foundNextCircle(currentListFriends); listGuests = listGuests.concat(currentListFriends); } - if (usedFriendNames.length !== listAllPersons.length && listGuests.length !== 0) { - currentListFriends = foundIncoherentFriends(); - listGuests = listGuests.concat(currentListFriends); - } + // if (usedFriendNames.length !== listAllPersons.length && listGuests.length !== 0) { + // currentListFriends = foundIncoherentFriends(); + // listGuests = listGuests.concat(currentListFriends); + // } return listGuests; } From 7dca655c5d0aad5bc1b9ee80ee0bea8dcac46f25 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 10:41:30 +0500 Subject: [PATCH 09/34] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D1=83=20=D0=B2=20=D0=BA=D0=B0=D0=B6=D0=B4=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=83=D1=80=D0=BE=D0=B2=D0=B5=D0=BD=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib.js b/lib.js index 198b8cd..66bbd4b 100644 --- a/lib.js +++ b/lib.js @@ -53,7 +53,7 @@ function foundNextCircle(currentListFriends) { hasCircle = false; } - return ansList; + return ansList.sort(compareAlphabetically); } /* function foundIncoherentFriends() { @@ -79,10 +79,6 @@ function getListGuest() { currentListFriends = foundNextCircle(currentListFriends); listGuests = listGuests.concat(currentListFriends); } - // if (usedFriendNames.length !== listAllPersons.length && listGuests.length !== 0) { - // currentListFriends = foundIncoherentFriends(); - // listGuests = listGuests.concat(currentListFriends); - // } return listGuests; } @@ -134,10 +130,10 @@ function getListLimitGuest(maxLevel) { } function LimitedIterator(friends, filter, maxLevel) { - maxLevel = maxLevel === undefined ? 0 : maxLevel; + maxLevel = maxLevel === (undefined || null) ? 0 : maxLevel; countCircles = 0; usedFriendNames = []; - listAllPersons = friends; + listAllPersons = friends.slice(); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } From 2291edbaca02442c08bb22733e73351bdc44469a Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 10:52:52 +0500 Subject: [PATCH 10/34] =?UTF-8?q?=D0=92=D0=BA=D0=BB=D1=8E=D1=87=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BB=D1=83=D1=87=D1=88=D0=B8=D1=85=20=D0=B4?= =?UTF-8?q?=D1=80=D1=83=D0=B7=D0=B5=D0=B9=20=D0=B2=20=D1=86=D0=B8=D0=BA?= =?UTF-8?q?=D0=BB=20while?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib.js b/lib.js index 66bbd4b..48cf114 100644 --- a/lib.js +++ b/lib.js @@ -53,7 +53,7 @@ function foundNextCircle(currentListFriends) { hasCircle = false; } - return ansList.sort(compareAlphabetically); + return ansList; } /* function foundIncoherentFriends() { @@ -69,8 +69,9 @@ function getListGuest() { return person.name; }); var listGuests = [].concat(listBestFriends); - var currentListFriends = foundNextCircle(listBestFriends); - listGuests = listGuests.concat(currentListFriends); + // var currentListFriends = foundNextCircle(listBestFriends); + // listGuests = listGuests.concat(currentListFriends); + var currentListFriends = listBestFriends; if (listGuests.length === 0) { hasCircle = false; } @@ -118,8 +119,9 @@ function getListLimitGuest(maxLevel) { }); var listGuests = [].concat(listBestFriends); if (maxLevel > 1) { - var currentListFriends = foundNextCircle(listBestFriends); - listGuests = listGuests.concat(currentListFriends); + // var currentListFriends = foundNextCircle(listBestFriends); + // listGuests = listGuests.concat(currentListFriends); + var currentListFriends = listBestFriends; while (countCircles < maxLevel) { currentListFriends = foundNextCircle(currentListFriends); listGuests = listGuests.concat(currentListFriends); From b4ae116429f1055f4272938cf382d680f1740911 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 10:58:33 +0500 Subject: [PATCH 11/34] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=81=D0=B0=D1=82=D0=BD=D0=B2=D0=BE?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BB=D0=B8=D0=BC=D0=B8=D1=82=D0=B0?= 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 48cf114..abae38e 100644 --- a/lib.js +++ b/lib.js @@ -122,7 +122,7 @@ function getListLimitGuest(maxLevel) { // var currentListFriends = foundNextCircle(listBestFriends); // listGuests = listGuests.concat(currentListFriends); var currentListFriends = listBestFriends; - while (countCircles < maxLevel) { + while (countCircles < maxLevel && usedFriendNames.length !== listAllPersons.length) { currentListFriends = foundNextCircle(currentListFriends); listGuests = listGuests.concat(currentListFriends); } From 08a75a95b74e71ffd1cfa24760f9e6251348a0f4 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 11:02:41 +0500 Subject: [PATCH 12/34] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=BE=D1=87=D0=B8=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B8=D0=B2=D0=B0=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.js b/lib.js index abae38e..3062a07 100644 --- a/lib.js +++ b/lib.js @@ -134,7 +134,7 @@ function getListLimitGuest(maxLevel) { function LimitedIterator(friends, filter, maxLevel) { maxLevel = maxLevel === (undefined || null) ? 0 : maxLevel; countCircles = 0; - usedFriendNames = []; + // usedFriendNames = []; listAllPersons = friends.slice(); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); From 16004c08c80a8377ac3f8ba074ba1be8a11ab3b3 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 11:09:18 +0500 Subject: [PATCH 13/34] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BF=D1=80=D0=B2=D0=B5=D1=80=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E=D1=89=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=83=D1=80=D0=BE=D0=B2=D0=BD=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib.js b/lib.js index 3062a07..d8d6e98 100644 --- a/lib.js +++ b/lib.js @@ -69,8 +69,6 @@ function getListGuest() { return person.name; }); var listGuests = [].concat(listBestFriends); - // var currentListFriends = foundNextCircle(listBestFriends); - // listGuests = listGuests.concat(currentListFriends); var currentListFriends = listBestFriends; if (listGuests.length === 0) { hasCircle = false; @@ -113,16 +111,15 @@ Iterator.prototype.next = function () { */ function getListLimitGuest(maxLevel) { + hasCircle = true; var listBestFriends = [].concat(foundFirstCircle()); usedFriendNames = listBestFriends.map(function (person) { return person.name; }); var listGuests = [].concat(listBestFriends); if (maxLevel > 1) { - // var currentListFriends = foundNextCircle(listBestFriends); - // listGuests = listGuests.concat(currentListFriends); var currentListFriends = listBestFriends; - while (countCircles < maxLevel && usedFriendNames.length !== listAllPersons.length) { + while (countCircles < maxLevel && hasCircle) { currentListFriends = foundNextCircle(currentListFriends); listGuests = listGuests.concat(currentListFriends); } @@ -134,7 +131,6 @@ function getListLimitGuest(maxLevel) { function LimitedIterator(friends, filter, maxLevel) { maxLevel = maxLevel === (undefined || null) ? 0 : maxLevel; countCircles = 0; - // usedFriendNames = []; listAllPersons = friends.slice(); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); From 3a81ef2a0d1129ff90a33d8af3a80feefc3daaa3 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 11:12:42 +0500 Subject: [PATCH 14/34] =?UTF-8?q?=D0=9F=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=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 d8d6e98..61067a4 100644 --- a/lib.js +++ b/lib.js @@ -117,7 +117,7 @@ function getListLimitGuest(maxLevel) { return person.name; }); var listGuests = [].concat(listBestFriends); - if (maxLevel > 1) { + if (maxLevel >= 1) { var currentListFriends = listBestFriends; while (countCircles < maxLevel && hasCircle) { currentListFriends = foundNextCircle(currentListFriends); From ef9f066e430b1305bcb67a5c383a919691de38a2 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 13:57:57 +0500 Subject: [PATCH 15/34] =?UTF-8?q?=D0=9E=D0=B1=D1=8A=D0=B5=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB=D0=B0=20=D0=B2=20=D0=BE=D0=B1=D1=89=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 56 +++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/lib.js b/lib.js index 61067a4..bb68fe1 100644 --- a/lib.js +++ b/lib.js @@ -8,9 +8,7 @@ */ var listAllPersons; var usedFriendNames; -var countCircles; -var hasCircle; - +// var countCircles; function compareAlphabetically(person1, person2) { if (person1.name > person2.name) { return 1; @@ -23,7 +21,7 @@ function compareAlphabetically(person1, person2) { } function foundFirstCircle() { - countCircles++; + // countCircles++; return listAllPersons.filter(function (person) { return person.best === true; @@ -31,7 +29,7 @@ function foundFirstCircle() { } function foundNextCircle(currentListFriends) { - countCircles++; + // countCircles++; var namesFriends = []; currentListFriends.forEach(function (person) { for (var i = 0; i < person.friends.length; i++) { @@ -49,32 +47,35 @@ function foundNextCircle(currentListFriends) { return (namesFriends.indexOf(person.name) !== -1 && !usedName); }).sort(compareAlphabetically); - if (ansList.length === 0) { - hasCircle = false; - } return ansList; } -/* function foundIncoherentFriends() { - return listAllPersons.filter(function (person) { - return usedFriendNames.indexOf(person.name) === -1; - }).sort(compareAlphabetically); -}*/ - -function getListGuest() { - hasCircle = true; +/* function getListGuest() { var listBestFriends = [].concat(foundFirstCircle()); usedFriendNames = listBestFriends.map(function (person) { return person.name; }); var listGuests = [].concat(listBestFriends); var currentListFriends = listBestFriends; - if (listGuests.length === 0) { - hasCircle = false; + + while (currentListFriends.length !== 0) { + currentListFriends = foundNextCircle(currentListFriends); + listGuests = listGuests.concat(currentListFriends); } - while (currentListFriends.length !== 0 && hasCircle) { + return listGuests; +}*/ + +function getGuests(maxLevel) { + var listBestFriends = [].concat(foundFirstCircle()); + usedFriendNames = listBestFriends.map(function (person) { + return person.name; + }); + var listGuests = [].concat(listBestFriends); + var currentListFriends = listBestFriends; + while (maxLevel > 1 && currentListFriends.length !== 0) { + maxLevel--; currentListFriends = foundNextCircle(currentListFriends); listGuests = listGuests.concat(currentListFriends); } @@ -88,14 +89,13 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } - this.listGuests = getListGuest(); - this.listGuests = this.listGuests.filter(function (friend) { + this.listGuests = getGuests(Infinity).filter(function (friend) { return filter.filterFriends(friend); }); this.listGuests.reverse(); } Iterator.prototype.done = function () { - return this.listGuests.length === 0; + return (this.listGuests.length === 0); }; Iterator.prototype.next = function () { return this.done() ? null : this.listGuests.pop(); @@ -110,8 +110,7 @@ Iterator.prototype.next = function () { * @param {Number} maxLevel – максимальный круг друзей */ -function getListLimitGuest(maxLevel) { - hasCircle = true; +/* function getListLimitGuest(maxLevel) { var listBestFriends = [].concat(foundFirstCircle()); usedFriendNames = listBestFriends.map(function (person) { return person.name; @@ -119,18 +118,18 @@ function getListLimitGuest(maxLevel) { var listGuests = [].concat(listBestFriends); if (maxLevel >= 1) { var currentListFriends = listBestFriends; - while (countCircles < maxLevel && hasCircle) { + while (countCircles < maxLevel) { currentListFriends = foundNextCircle(currentListFriends); listGuests = listGuests.concat(currentListFriends); } } return listGuests; -} +}*/ function LimitedIterator(friends, filter, maxLevel) { maxLevel = maxLevel === (undefined || null) ? 0 : maxLevel; - countCircles = 0; + // countCircles = 0; listAllPersons = friends.slice(); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); @@ -138,8 +137,7 @@ function LimitedIterator(friends, filter, maxLevel) { if (maxLevel <= 0) { this.listGuests = []; } else { - this.listGuests = getListLimitGuest(maxLevel); - this.listGuests = this.listGuests.filter(function (friend) { + this.listGuests = getGuests(maxLevel).filter(function (friend) { return filter.filterFriends(friend); }); this.listGuests.reverse(); From 271f290ec7e1dda67b632f3f8833ba45f2c0df3d Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 14:08:27 +0500 Subject: [PATCH 16/34] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BB=D0=B8=D0=BC=D0=B8=D1=82=D0=B0=20und?= =?UTF-8?q?efined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/lib.js b/lib.js index bb68fe1..0bc1777 100644 --- a/lib.js +++ b/lib.js @@ -8,7 +8,6 @@ */ var listAllPersons; var usedFriendNames; -// var countCircles; function compareAlphabetically(person1, person2) { if (person1.name > person2.name) { return 1; @@ -21,15 +20,12 @@ function compareAlphabetically(person1, person2) { } function foundFirstCircle() { - // countCircles++; - return listAllPersons.filter(function (person) { return person.best === true; }).sort(compareAlphabetically); } function foundNextCircle(currentListFriends) { - // countCircles++; var namesFriends = []; currentListFriends.forEach(function (person) { for (var i = 0; i < person.friends.length; i++) { @@ -51,22 +47,6 @@ function foundNextCircle(currentListFriends) { return ansList; } -/* function getListGuest() { - var listBestFriends = [].concat(foundFirstCircle()); - usedFriendNames = listBestFriends.map(function (person) { - return person.name; - }); - var listGuests = [].concat(listBestFriends); - var currentListFriends = listBestFriends; - - while (currentListFriends.length !== 0) { - currentListFriends = foundNextCircle(currentListFriends); - listGuests = listGuests.concat(currentListFriends); - } - - return listGuests; -}*/ - function getGuests(maxLevel) { var listBestFriends = [].concat(foundFirstCircle()); usedFriendNames = listBestFriends.map(function (person) { @@ -95,7 +75,7 @@ function Iterator(friends, filter) { this.listGuests.reverse(); } Iterator.prototype.done = function () { - return (this.listGuests.length === 0); + return this.listGuests.length === 0; }; Iterator.prototype.next = function () { return this.done() ? null : this.listGuests.pop(); @@ -110,26 +90,8 @@ Iterator.prototype.next = function () { * @param {Number} maxLevel – максимальный круг друзей */ -/* function getListLimitGuest(maxLevel) { - var listBestFriends = [].concat(foundFirstCircle()); - usedFriendNames = listBestFriends.map(function (person) { - return person.name; - }); - var listGuests = [].concat(listBestFriends); - if (maxLevel >= 1) { - var currentListFriends = listBestFriends; - while (countCircles < maxLevel) { - currentListFriends = foundNextCircle(currentListFriends); - listGuests = listGuests.concat(currentListFriends); - } - } - - return listGuests; -}*/ - function LimitedIterator(friends, filter, maxLevel) { - maxLevel = maxLevel === (undefined || null) ? 0 : maxLevel; - // countCircles = 0; + maxLevel = (typeof maxLevel === 'undefined') ? 0 : maxLevel; listAllPersons = friends.slice(); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); From d6dc826692503529625b4c0f4333a64995b670d5 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 15:38:46 +0500 Subject: [PATCH 17/34] =?UTF-8?q?=D0=9D=D0=B5=D1=81=D0=BA=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=BA=D0=BE=20=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D1=85=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib.js b/lib.js index 0bc1777..b6a66f2 100644 --- a/lib.js +++ b/lib.js @@ -54,8 +54,9 @@ function getGuests(maxLevel) { }); var listGuests = [].concat(listBestFriends); var currentListFriends = listBestFriends; - while (maxLevel > 1 && currentListFriends.length !== 0) { - maxLevel--; + var level = maxLevel; + while (level > 1 && currentListFriends.length !== 0) { + level--; currentListFriends = foundNextCircle(currentListFriends); listGuests = listGuests.concat(currentListFriends); } @@ -64,21 +65,32 @@ function getGuests(maxLevel) { } function Iterator(friends, filter) { - usedFriendNames = []; + // usedFriendNames = []; listAllPersons = friends.slice(); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } + this.indexPersons = 0; this.listGuests = getGuests(Infinity).filter(function (friend) { return filter.filterFriends(friend); }); this.listGuests.reverse(); } Iterator.prototype.done = function () { - return this.listGuests.length === 0; + // return this.listGuests.length === 0; + + return this.indexPersons >= this.listGuests.length; }; Iterator.prototype.next = function () { - return this.done() ? null : this.listGuests.pop(); + if (this.done()) { + return null; + } + + // return this.listGuests.pop(); + var index = this.indexPersons++; + + return this.listGuests[this.listGuests.length - index - 1]; + // return this.done() ? null : this.listGuests.pop(); }; /** @@ -99,6 +111,8 @@ function LimitedIterator(friends, filter, maxLevel) { if (maxLevel <= 0) { this.listGuests = []; } else { + + this.indexPersons = 0; this.listGuests = getGuests(maxLevel).filter(function (friend) { return filter.filterFriends(friend); }); From 458d0a0bfe2953165e78760f542fe42eabc7eb4a Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 15:44:48 +0500 Subject: [PATCH 18/34] =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib.js b/lib.js index b6a66f2..3d303d6 100644 --- a/lib.js +++ b/lib.js @@ -70,26 +70,26 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } - this.indexPersons = 0; + // this.indexPersons = 0; this.listGuests = getGuests(Infinity).filter(function (friend) { return filter.filterFriends(friend); }); this.listGuests.reverse(); } Iterator.prototype.done = function () { - // return this.listGuests.length === 0; + return this.listGuests.length <= 0; - return this.indexPersons >= this.listGuests.length; + // return this.indexPersons >= this.listGuests.length; }; Iterator.prototype.next = function () { if (this.done()) { return null; } - // return this.listGuests.pop(); - var index = this.indexPersons++; + return this.listGuests.pop(); + // var index = this.indexPersons++; - return this.listGuests[this.listGuests.length - index - 1]; + // return this.listGuests[this.listGuests.length - index - 1]; // return this.done() ? null : this.listGuests.pop(); }; @@ -112,7 +112,7 @@ function LimitedIterator(friends, filter, maxLevel) { this.listGuests = []; } else { - this.indexPersons = 0; + // this.indexPersons = 0; this.listGuests = getGuests(maxLevel).filter(function (friend) { return filter.filterFriends(friend); }); From 53ac4fd829ddc8e1a716d732db921e54a742b262 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 15:58:11 +0500 Subject: [PATCH 19/34] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=86=D0=B8=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=20while?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib.js b/lib.js index 3d303d6..8486a42 100644 --- a/lib.js +++ b/lib.js @@ -52,13 +52,14 @@ function getGuests(maxLevel) { usedFriendNames = listBestFriends.map(function (person) { return person.name; }); - var listGuests = [].concat(listBestFriends); + // var listGuests = [].concat(listBestFriends); + var listGuests = []; var currentListFriends = listBestFriends; var level = maxLevel; - while (level > 1 && currentListFriends.length !== 0) { - level--; - currentListFriends = foundNextCircle(currentListFriends); + while (level > 0 && currentListFriends.length !== 0) { listGuests = listGuests.concat(currentListFriends); + currentListFriends = foundNextCircle(currentListFriends); + level--; } return listGuests; From 94c50f3fb5801fb642219203a048d5d54bcf318f Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 16:36:58 +0500 Subject: [PATCH 20/34] =?UTF-8?q?=D0=90=D1=80=D0=B3=D1=83=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=20=D1=82=D0=BE=D0=B6=D0=B5=20=D1=81=D0=BE=D1=80?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D1=83=D1=8E=20=D0=BF=D0=BE=20=D0=B0=D0=BB?= =?UTF-8?q?=D1=84=D0=B0=D0=B2=D0=B8=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib.js b/lib.js index 8486a42..57a5a77 100644 --- a/lib.js +++ b/lib.js @@ -54,11 +54,11 @@ function getGuests(maxLevel) { }); // var listGuests = [].concat(listBestFriends); var listGuests = []; - var currentListFriends = listBestFriends; + var currentListFriends = listBestFriends.sort(compareAlphabetically); var level = maxLevel; while (level > 0 && currentListFriends.length !== 0) { listGuests = listGuests.concat(currentListFriends); - currentListFriends = foundNextCircle(currentListFriends); + currentListFriends = foundNextCircle(currentListFriends.sort(compareAlphabetically)); level--; } From 02b16b413535ead3a453aec52fb853aabdadb905 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 17:02:27 +0500 Subject: [PATCH 21/34] =?UTF-8?q?=D0=9E=D0=B1=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BD=D0=B5=D1=81=D0=B2=D1=8F=D0=B7=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib.js b/lib.js index 57a5a77..a8c5412 100644 --- a/lib.js +++ b/lib.js @@ -27,7 +27,7 @@ function foundFirstCircle() { function foundNextCircle(currentListFriends) { var namesFriends = []; - currentListFriends.forEach(function (person) { + currentListFriends.sort(compareAlphabetically).forEach(function (person) { for (var i = 0; i < person.friends.length; i++) { if (namesFriends.indexOf(person.friends[i]) === -1) { namesFriends.push(person.friends[i]); @@ -44,7 +44,9 @@ function foundNextCircle(currentListFriends) { return (namesFriends.indexOf(person.name) !== -1 && !usedName); }).sort(compareAlphabetically); - return ansList; + return ansList.filter(function (person) { + return usedFriendNames.indexOf(person.name) !== -1; + }).sort(compareAlphabetically); } function getGuests(maxLevel) { From ed41213f470ea7ff5bb44229bffc666ec4f8933b Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 17:10:59 +0500 Subject: [PATCH 22/34] =?UTF-8?q?=D0=92=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib.js b/lib.js index a8c5412..78d12e3 100644 --- a/lib.js +++ b/lib.js @@ -44,9 +44,7 @@ function foundNextCircle(currentListFriends) { return (namesFriends.indexOf(person.name) !== -1 && !usedName); }).sort(compareAlphabetically); - return ansList.filter(function (person) { - return usedFriendNames.indexOf(person.name) !== -1; - }).sort(compareAlphabetically); + return ansList; } function getGuests(maxLevel) { @@ -64,7 +62,9 @@ function getGuests(maxLevel) { level--; } - return listGuests; + return listGuests.filter(function (person) { + return usedFriendNames.indexOf(person.name) !== -1; + }); } function Iterator(friends, filter) { From 01f27cb0a14290c23653572bb4e523c66fdba42a Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 17:14:08 +0500 Subject: [PATCH 23/34] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=B8=D0=B7=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=B2=D1=8F=D0=B7=D0=BD=D1=8B=D1=85=20=D0=B4=D1=80?= =?UTF-8?q?=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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.js b/lib.js index 78d12e3..e36df46 100644 --- a/lib.js +++ b/lib.js @@ -63,7 +63,7 @@ function getGuests(maxLevel) { } return listGuests.filter(function (person) { - return usedFriendNames.indexOf(person.name) !== -1; + return person.friends.length !== 0; }); } From e12cd2fe3a4f8c11149889baca8eee79b10b2eaa Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 17:39:03 +0500 Subject: [PATCH 24/34] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=BB=D0=B8=D1=88=D0=BD=D0=B8=D1=85=20=D0=BB=D1=8E=D0=B4=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=B8=D0=B7=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib.js b/lib.js index e36df46..1f889b1 100644 --- a/lib.js +++ b/lib.js @@ -36,13 +36,17 @@ function foundNextCircle(currentListFriends) { }); var ansList = listAllPersons.filter(function (person) { + var along = person.friends.length === 0; var usedName = usedFriendNames.indexOf(person.name) !== -1; - if (namesFriends.indexOf(person.name) !== -1 && !usedName) { + if (namesFriends.indexOf(person.name) !== -1 && !usedName && !along) { usedFriendNames.push(person.name); } return (namesFriends.indexOf(person.name) !== -1 && !usedName); }).sort(compareAlphabetically); + ansList.forEach(function (person) { + person.level++; + }); return ansList; } @@ -63,13 +67,16 @@ function getGuests(maxLevel) { } return listGuests.filter(function (person) { - return person.friends.length !== 0; + return person.level !== 0; }); } function Iterator(friends, filter) { // usedFriendNames = []; listAllPersons = friends.slice(); + listAllPersons.forEach(function (friend) { + friend.level = friend.best ? 1 : 0; + }); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } From c6e0ca2ba5e6559e9a34fa3e36f26169d6192469 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 22:08:28 +0500 Subject: [PATCH 25/34] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=B3=D0=BB=D0=BE=D0=B1=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20=D0=B8=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D1=8F=D1=8E=D1=89=D0=B8=D0=B9=D1=81?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/lib.js b/lib.js index 1f889b1..5d43587 100644 --- a/lib.js +++ b/lib.js @@ -6,7 +6,7 @@ * @param {Object[]} friends * @param {Filter} filter */ -var listAllPersons; +// var listAllPersons; var usedFriendNames; function compareAlphabetically(person1, person2) { if (person1.name > person2.name) { @@ -19,13 +19,13 @@ function compareAlphabetically(person1, person2) { return 0; } -function foundFirstCircle() { - return listAllPersons.filter(function (person) { +function foundFirstCircle(friends) { + return friends.filter(function (person) { return person.best === true; }).sort(compareAlphabetically); } -function foundNextCircle(currentListFriends) { +function foundNextCircle(friends, currentListFriends) { var namesFriends = []; currentListFriends.sort(compareAlphabetically).forEach(function (person) { for (var i = 0; i < person.friends.length; i++) { @@ -35,7 +35,7 @@ function foundNextCircle(currentListFriends) { } }); - var ansList = listAllPersons.filter(function (person) { + var ansList = friends.filter(function (person) { var along = person.friends.length === 0; var usedName = usedFriendNames.indexOf(person.name) !== -1; if (namesFriends.indexOf(person.name) !== -1 && !usedName && !along) { @@ -44,46 +44,37 @@ function foundNextCircle(currentListFriends) { return (namesFriends.indexOf(person.name) !== -1 && !usedName); }).sort(compareAlphabetically); - ansList.forEach(function (person) { - person.level++; - }); return ansList; } -function getGuests(maxLevel) { - var listBestFriends = [].concat(foundFirstCircle()); +function getGuests(friends, filter, maxLevel) { + var listBestFriends = [].concat(foundFirstCircle(friends)); usedFriendNames = listBestFriends.map(function (person) { return person.name; }); - // var listGuests = [].concat(listBestFriends); var listGuests = []; - var currentListFriends = listBestFriends.sort(compareAlphabetically); + var currListFriends = listBestFriends.sort(compareAlphabetically); var level = maxLevel; - while (level > 0 && currentListFriends.length !== 0) { - listGuests = listGuests.concat(currentListFriends); - currentListFriends = foundNextCircle(currentListFriends.sort(compareAlphabetically)); + while (level > 0 && currListFriends.length !== 0) { + listGuests = listGuests.concat(currListFriends); + currListFriends = foundNextCircle(friends, currListFriends.sort(compareAlphabetically)); level--; } - return listGuests.filter(function (person) { - return person.level !== 0; + return listGuests.filter(function (friend) { + return filter.filterFriends(friend); }); } function Iterator(friends, filter) { // usedFriendNames = []; - listAllPersons = friends.slice(); - listAllPersons.forEach(function (friend) { - friend.level = friend.best ? 1 : 0; - }); + // listAllPersons = friends.slice(); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } // this.indexPersons = 0; - this.listGuests = getGuests(Infinity).filter(function (friend) { - return filter.filterFriends(friend); - }); + this.listGuests = getGuests(friends, filter, Infinity); this.listGuests.reverse(); } Iterator.prototype.done = function () { @@ -114,7 +105,7 @@ Iterator.prototype.next = function () { function LimitedIterator(friends, filter, maxLevel) { maxLevel = (typeof maxLevel === 'undefined') ? 0 : maxLevel; - listAllPersons = friends.slice(); + // listAllPersons = friends.slice(); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } @@ -123,9 +114,7 @@ function LimitedIterator(friends, filter, maxLevel) { } else { // this.indexPersons = 0; - this.listGuests = getGuests(maxLevel).filter(function (friend) { - return filter.filterFriends(friend); - }); + this.listGuests = getGuests(friends, filter, maxLevel); this.listGuests.reverse(); } } From f172018fce6315d8ab5eb2b99c3dffdcee818bbc Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 23:15:41 +0500 Subject: [PATCH 26/34] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BB=D0=B0=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20get?= =?UTF-8?q?NextCircle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 64 +++++++++++++++++++++------------------------------------- 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/lib.js b/lib.js index 5d43587..12365d6 100644 --- a/lib.js +++ b/lib.js @@ -6,8 +6,7 @@ * @param {Object[]} friends * @param {Filter} filter */ -// var listAllPersons; -var usedFriendNames; + function compareAlphabetically(person1, person2) { if (person1.name > person2.name) { return 1; @@ -19,46 +18,38 @@ function compareAlphabetically(person1, person2) { return 0; } -function foundFirstCircle(friends) { +function getFirstCircle(friends) { return friends.filter(function (person) { return person.best === true; }).sort(compareAlphabetically); } -function foundNextCircle(friends, currentListFriends) { - var namesFriends = []; - currentListFriends.sort(compareAlphabetically).forEach(function (person) { - for (var i = 0; i < person.friends.length; i++) { - if (namesFriends.indexOf(person.friends[i]) === -1) { - namesFriends.push(person.friends[i]); - } +function getNextCircle(friends, currFriends, listGuests) { + currFriends.sort(compareAlphabetically).forEach(function (person) { + if (listGuests.indexOf(person) === -1) { + listGuests.push(person); + person.friends.forEach(function (name) { + var guest = friends.filter(function (friend) { + return friend.name === name; + })[0]; + currFriends.push(guest); + }); } }); - var ansList = friends.filter(function (person) { - var along = person.friends.length === 0; - var usedName = usedFriendNames.indexOf(person.name) !== -1; - if (namesFriends.indexOf(person.name) !== -1 && !usedName && !along) { - usedFriendNames.push(person.name); - } - - return (namesFriends.indexOf(person.name) !== -1 && !usedName); - }).sort(compareAlphabetically); - - return ansList; + return [currFriends, listGuests]; } function getGuests(friends, filter, maxLevel) { - var listBestFriends = [].concat(foundFirstCircle(friends)); - usedFriendNames = listBestFriends.map(function (person) { - return person.name; - }); + var currFriends = [].concat(getFirstCircle(friends)); var listGuests = []; - var currListFriends = listBestFriends.sort(compareAlphabetically); var level = maxLevel; - while (level > 0 && currListFriends.length !== 0) { - listGuests = listGuests.concat(currListFriends); - currListFriends = foundNextCircle(friends, currListFriends.sort(compareAlphabetically)); + while (level > 0 && currFriends.length !== 0) { + var countFriends = currFriends.length; + var resultNextCircle = getNextCircle (friends, currFriends, listGuests); + currFriends = resultNextCircle[0]; + listGuests = resultNextCircle[1]; + currFriends.splice(0, countFriends); level--; } @@ -68,30 +59,24 @@ function getGuests(friends, filter, maxLevel) { } function Iterator(friends, filter) { - // usedFriendNames = []; - // listAllPersons = friends.slice(); + if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } - // this.indexPersons = 0; this.listGuests = getGuests(friends, filter, Infinity); this.listGuests.reverse(); } + Iterator.prototype.done = function () { return this.listGuests.length <= 0; - - // return this.indexPersons >= this.listGuests.length; }; + Iterator.prototype.next = function () { if (this.done()) { return null; } return this.listGuests.pop(); - // var index = this.indexPersons++; - - // return this.listGuests[this.listGuests.length - index - 1]; - // return this.done() ? null : this.listGuests.pop(); }; /** @@ -105,15 +90,12 @@ Iterator.prototype.next = function () { function LimitedIterator(friends, filter, maxLevel) { maxLevel = (typeof maxLevel === 'undefined') ? 0 : maxLevel; - // listAllPersons = friends.slice(); if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } if (maxLevel <= 0) { this.listGuests = []; } else { - - // this.indexPersons = 0; this.listGuests = getGuests(friends, filter, maxLevel); this.listGuests.reverse(); } From 682d606fb9678c3fa031500cc9de7a7020c206b1 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 23:28:26 +0500 Subject: [PATCH 27/34] =?UTF-8?q?=D0=92=D0=B5=D1=80=D0=BD=D1=83=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=BE=D0=B4=D1=81=D1=87=D0=B5=D1=82=20=D0=B8?= =?UTF-8?q?=D0=BD=D0=B4=D0=B5=D0=BA=D1=81=D0=B0,=20=D1=83=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0=20reverse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib.js b/lib.js index 12365d6..cb5bc5a 100644 --- a/lib.js +++ b/lib.js @@ -63,12 +63,14 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } + this.currIndex = 0; this.listGuests = getGuests(friends, filter, Infinity); - this.listGuests.reverse(); + // this.listGuests.reverse(); } Iterator.prototype.done = function () { - return this.listGuests.length <= 0; + // return this.listGuests.length <= 0; + return this.currIndex >= this.listGuests.length; }; Iterator.prototype.next = function () { @@ -76,7 +78,8 @@ Iterator.prototype.next = function () { return null; } - return this.listGuests.pop(); + return this.listGuests[this.currIndex++]; + // return this.listGuests.pop(); }; /** @@ -96,8 +99,9 @@ function LimitedIterator(friends, filter, maxLevel) { if (maxLevel <= 0) { this.listGuests = []; } else { + this.currIndex = 0; this.listGuests = getGuests(friends, filter, maxLevel); - this.listGuests.reverse(); + // this.listGuests.reverse(); } } From 5296b1669761795f79eb9f6c5be74b87eb70c457 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 23:38:48 +0500 Subject: [PATCH 28/34] =?UTF-8?q?=D0=9E=D1=82=D0=BA=D0=B0=D1=82=20+=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D0=B0=20=D1=81?= =?UTF-8?q?=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lib.js b/lib.js index cb5bc5a..7f3ea22 100644 --- a/lib.js +++ b/lib.js @@ -8,14 +8,7 @@ */ function compareAlphabetically(person1, person2) { - if (person1.name > person2.name) { - return 1; - } - if (person1.name < person2.name) { - return -1; - } - - return 0; + return person1.name.localeCompare(person2.name); } function getFirstCircle(friends) { @@ -63,14 +56,14 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } - this.currIndex = 0; + // this.currIndex = 0; this.listGuests = getGuests(friends, filter, Infinity); - // this.listGuests.reverse(); + this.listGuests.reverse(); } Iterator.prototype.done = function () { - // return this.listGuests.length <= 0; - return this.currIndex >= this.listGuests.length; + return this.listGuests.length <= 0; + // return this.currIndex >= this.listGuests.length; }; Iterator.prototype.next = function () { @@ -78,8 +71,8 @@ Iterator.prototype.next = function () { return null; } - return this.listGuests[this.currIndex++]; - // return this.listGuests.pop(); + // return this.listGuests[this.currIndex++]; + return this.listGuests.pop(); }; /** @@ -99,9 +92,9 @@ function LimitedIterator(friends, filter, maxLevel) { if (maxLevel <= 0) { this.listGuests = []; } else { - this.currIndex = 0; + // this.currIndex = 0; this.listGuests = getGuests(friends, filter, maxLevel); - // this.listGuests.reverse(); + this.listGuests.reverse(); } } From b0f570c690fbde27cd6225468b58e6ef81d0fb1a Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 23:42:49 +0500 Subject: [PATCH 29/34] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=BB=D0=B8=D1=88=D0=BD=D0=B8=D0=B5=20=D1=83=D1=81=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=D0=B8=D1=8F=20=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib.js b/lib.js index 7f3ea22..b5abcec 100644 --- a/lib.js +++ b/lib.js @@ -8,7 +8,14 @@ */ function compareAlphabetically(person1, person2) { - return person1.name.localeCompare(person2.name); + if (person1.name > person2.name) { + return 1; + } + if (person1.name < person2.name) { + return -1; + } + + return 0; } function getFirstCircle(friends) { @@ -56,14 +63,12 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } - // this.currIndex = 0; this.listGuests = getGuests(friends, filter, Infinity); this.listGuests.reverse(); } Iterator.prototype.done = function () { return this.listGuests.length <= 0; - // return this.currIndex >= this.listGuests.length; }; Iterator.prototype.next = function () { @@ -71,7 +76,6 @@ Iterator.prototype.next = function () { return null; } - // return this.listGuests[this.currIndex++]; return this.listGuests.pop(); }; @@ -89,13 +93,8 @@ function LimitedIterator(friends, filter, maxLevel) { if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } - if (maxLevel <= 0) { - this.listGuests = []; - } else { - // this.currIndex = 0; - this.listGuests = getGuests(friends, filter, maxLevel); - this.listGuests.reverse(); - } + this.listGuests = getGuests(friends, filter, maxLevel); + this.listGuests.reverse(); } LimitedIterator.prototype = Object.create(Iterator.prototype); From 437a2b45cbf3b4fb993d0187f5b48980027af314 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 23:55:16 +0500 Subject: [PATCH 30/34] =?UTF-8?q?=D0=9E=D1=82=D1=87=D0=B0=D1=8F=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=8C=20=D0=BD=D0=B0=D0=B9=D1=82=D0=B8=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib.js b/lib.js index b5abcec..efb7546 100644 --- a/lib.js +++ b/lib.js @@ -1,12 +1,5 @@ 'use strict'; -/** - * Итератор по друзьям - * @constructor - * @param {Object[]} friends - * @param {Filter} filter - */ - function compareAlphabetically(person1, person2) { if (person1.name > person2.name) { return 1; @@ -58,6 +51,13 @@ function getGuests(friends, filter, maxLevel) { }); } +/** + * Итератор по друзьям + * @constructor + * @param {Object[]} friends + * @param {Filter} filter + */ + function Iterator(friends, filter) { if (!(filter instanceof Filter)) { From e6a40878b20d99c186355cf863b2f0aa4964604f Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 23:57:54 +0500 Subject: [PATCH 31/34] =?UTF-8?q?=D0=9B=D0=B8=D1=88=D0=BD=D1=8F=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0?= 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 efb7546..67ecad2 100644 --- a/lib.js +++ b/lib.js @@ -14,7 +14,7 @@ function compareAlphabetically(person1, person2) { function getFirstCircle(friends) { return friends.filter(function (person) { return person.best === true; - }).sort(compareAlphabetically); + }); } function getNextCircle(friends, currFriends, listGuests) { From 49716fb47bf7fb48fda3d808ac45fc0269d5812c Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Wed, 23 Nov 2016 23:59:36 +0500 Subject: [PATCH 32/34] =?UTF-8?q?=D1=84=D0=B8=D0=BA=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 67ecad2..87641cf 100644 --- a/lib.js +++ b/lib.js @@ -76,7 +76,7 @@ Iterator.prototype.next = function () { return null; } - return this.listGuests.pop(); + return this.listGuests.pop() || null; }; /** From 2a847e042fb01eb26adefcf3ecd25762d16b0be6 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Thu, 24 Nov 2016 01:29:30 +0500 Subject: [PATCH 33/34] =?UTF-8?q?=D0=95=D1=89=D0=B5=20=D0=BE=D0=B4=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B0=20=D1=83?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D1=82=D1=8C=20reverse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib.js b/lib.js index 87641cf..8956d94 100644 --- a/lib.js +++ b/lib.js @@ -63,20 +63,25 @@ function Iterator(friends, filter) { if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } + this.index = 0; this.listGuests = getGuests(friends, filter, Infinity); - this.listGuests.reverse(); + // this.listGuests.reverse(); } Iterator.prototype.done = function () { - return this.listGuests.length <= 0; + // return this.listGuests.length <= 0; + return this.index === this.listGuests.length; }; Iterator.prototype.next = function () { if (this.done()) { return null; } + var guest = this.listGuests[this.index]; + this.index++; - return this.listGuests.pop() || null; + return guest; + // return this.listGuests.pop(); }; /** @@ -93,8 +98,9 @@ function LimitedIterator(friends, filter, maxLevel) { if (!(filter instanceof Filter)) { throw new TypeError('Incorrect data type Filter'); } + this.index = 0; this.listGuests = getGuests(friends, filter, maxLevel); - this.listGuests.reverse(); + // this.listGuests.reverse(); } LimitedIterator.prototype = Object.create(Iterator.prototype); From 6bb246c8799c9e1254dac3f9eed23c65540b3d83 Mon Sep 17 00:00:00 2001 From: MariaShmakova Date: Fri, 9 Dec 2016 13:46:26 +0500 Subject: [PATCH 34/34] =?UTF-8?q?=D0=92=D1=81=D0=BF=D0=BE=D0=BC=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D1=83=20?= =?UTF-8?q?=D0=B2=20=D0=BB=D1=83=D1=87=D1=88=D0=B8=D1=85=20=D0=B4=D1=80?= =?UTF-8?q?=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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.js b/lib.js index 8956d94..8ab020d 100644 --- a/lib.js +++ b/lib.js @@ -14,7 +14,7 @@ function compareAlphabetically(person1, person2) { function getFirstCircle(friends) { return friends.filter(function (person) { return person.best === true; - }); + }).sort(compareAlphabetically); } function getNextCircle(friends, currFriends, listGuests) {