Conversation
|
🍅 Пройдено тестов 10 из 24 |
|
🍅 Пройдено тестов 10 из 24 |
|
🍏 Пройдено тестов 24 из 24 |
lib.js
Outdated
| for (var j = 0; j < newLevelFriends.length; j++) { | ||
| friendsWithLevel.push( | ||
| { | ||
| friend: getFriendByName(friends, newLevelFriends[j]), |
There was a problem hiding this comment.
было бы круто избавиться от этой функции, например храня в newLevelFriends не только имена а сразу объект друга
| } | ||
|
|
||
| friendsWithLevel.sort(function (friendOne, friendTwo) { | ||
| if (friendOne.level > friendTwo.level) { |
There was a problem hiding this comment.
можно красиво сделать через тернарник
lib.js
Outdated
| function Iterator(friends, filter) { | ||
| console.info(friends, filter); | ||
| if (!Filter.prototype.isPrototypeOf(filter)) { | ||
| throw new TypeError(); |
lib.js
Outdated
| if (!Filter.prototype.isPrototypeOf(filter)) { | ||
| throw new TypeError(); | ||
| } | ||
| this.friendsWithLevel = friendsLevel(friends).filter(function (friend) { |
There was a problem hiding this comment.
все методы нужно разместить в прототипах
|
🍅 |
|
🍏 Пройдено тестов 24 из 24 |
|
🚀 |
| }; | ||
| } | ||
|
|
||
| MaleFilter.prototype = Object.create(Filter.prototype); |
There was a problem hiding this comment.
❗️ Свйоство (new MaleFilter()).contructor теперь указывает на Filter
|
|
||
| Iterator.prototype.friendsLevel = function (friends) { | ||
| var bestFriends = friends.filter(function (friend) { | ||
| return friend.hasOwnProperty('best') && friend.best; |
There was a problem hiding this comment.
В принципе, можно заменить на Boolean(friend.best)
| for (var i = 0; i < friendsWithLevel.length; i++) { | ||
| var newLevelFriends = | ||
| friendsWithLevel[i].friend.friends.reduce(function (newLevelFunction, friendName) { | ||
| if (namesOfFriends.indexOf(friendName) === -1) { |
There was a problem hiding this comment.
❗️ Лучше держать объект имен, по нему скорость поиска значительно выше
| } | ||
| ); | ||
| namesOfFriends.push(newLevelFriends[j].name); | ||
| } |
There was a problem hiding this comment.
❗️ Обычно цикл for используется для предсказуемого числа итераций. Тут явно не тот случай.
Я бы предложил использовать очередь, из которой выталкивать по одному элементу. Имеется фор по friendsWithLevel
| } | ||
|
|
||
| return (friendOne.friend.name > friendTwo.friend.name) ? 1 : -1; | ||
| }); |
There was a problem hiding this comment.
❗️ А можно без этой сортировки в конце обойтись?
No description provided.