Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

galkadaw
Copy link

No description provided.

@honest-hrundel
Copy link

🍅 Пройдено тестов 10 из 24

@honest-hrundel
Copy link

🍅 Пройдено тестов 10 из 24

@honest-hrundel
Copy link

🍏 Пройдено тестов 24 из 24

for (var j = 0; j < newLevelFriends.length; j++) {
friendsWithLevel.push(
{
friend: getFriendByName(friends, newLevelFriends[j]),

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) {

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();

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

все методы нужно разместить в прототипах

@FrodoTheTrue
Copy link

🍅

@honest-hrundel
Copy link

🍏 Пройдено тестов 24 из 24

@FrodoTheTrue
Copy link

🚀

@honest-hrundel honest-hrundel assigned dzlk and unassigned FrodoTheTrue Dec 3, 2016
Copy link

@dzlk dzlk left a 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);
Copy link

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;
Copy link

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) {
Copy link

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);
}
Copy link

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;
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗️ А можно без этой сортировки в конце обойтись?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants