-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Назарова Галина #9
base: master
Are you sure you want to change the base?
Conversation
🍅 Пройдено тестов 10 из 24 |
🍅 Пройдено тестов 10 из 24 |
🍏 Пройдено тестов 24 из 24 |
for (var j = 0; j < newLevelFriends.length; j++) { | ||
friendsWithLevel.push( | ||
{ | ||
friend: getFriendByName(friends, newLevelFriends[j]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
было бы круто избавиться от этой функции, например храня в newLevelFriends не только имена а сразу объект друга
} | ||
|
||
friendsWithLevel.sort(function (friendOne, friendTwo) { | ||
if (friendOne.level > friendTwo.level) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно красиво сделать через тернарник
/** | ||
* Итератор по друзьям | ||
* @constructor | ||
* @param {Object[]} friends | ||
* @param {Filter} filter | ||
*/ | ||
function Iterator(friends, filter) { | ||
console.info(friends, filter); | ||
if (!Filter.prototype.isPrototypeOf(filter)) { | ||
throw new TypeError(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше написать здесь ошибку
if (!Filter.prototype.isPrototypeOf(filter)) { | ||
throw new TypeError(); | ||
} | ||
this.friendsWithLevel = friendsLevel(friends).filter(function (friend) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
все методы нужно разместить в прототипах
🍅 |
🍏 Пройдено тестов 24 из 24 |
🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍅
} | ||
|
||
MaleFilter.prototype = Object.create(Filter.prototype); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗️ Свйоство (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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В принципе, можно заменить на 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗️ Лучше держать объект имен, по нему скорость поиска значительно выше
} | ||
); | ||
namesOfFriends.push(newLevelFriends[j].name); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗️ Обычно цикл for используется для предсказуемого числа итераций. Тут явно не тот случай.
Я бы предложил использовать очередь, из которой выталкивать по одному элементу. Имеется фор по friendsWithLevel
} | ||
|
||
return (friendOne.friend.name > friendTwo.friend.name) ? 1 : -1; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗️ А можно без этой сортировки в конце обойтись?
No description provided.