Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Квашнина Ульяна #43

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

Open
Uliana1997 wants to merge 18 commits into urfu-2016:master
base: master
Choose a base branch
Loading
from Uliana1997:master
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
63da3af
First
Uliana1997 Nov 2, 2016
38a3b74
Квашнина Ульяна
Uliana1997 Nov 2, 2016
b03ad97
Квашнина Ульяна
Uliana1997 Nov 2, 2016
d940bae
Квашнина Ульяна
Uliana1997 Nov 2, 2016
4dbb289
Квашнина Ульяна
Uliana1997 Nov 2, 2016
bbc6609
Квашнина Ульяна
Uliana1997 Nov 2, 2016
5fed378
Квашнина Ульяна
Uliana1997 Nov 2, 2016
69b2a4a
Квашнина Ульяна
Uliana1997 Nov 2, 2016
e4743a7
Квашнина ульяна
Uliana1997 Nov 2, 2016
e04b042
Квашнина Ульяна
Uliana1997 Nov 6, 2016
b139d4d
Квашнина Ульяна
Uliana1997 Nov 6, 2016
c980067
Квашнина Ульяна
Uliana1997 Nov 6, 2016
319c9fc
Квашнина Ульяна
Uliana1997 Nov 6, 2016
f1b443b
Квашнина Ульяна
Uliana1997 Nov 10, 2016
b0bb7b4
Квашнина Ульяна
Uliana1997 Nov 10, 2016
799aac8
Квашнина Ульяна
Uliana1997 Nov 10, 2016
80da510
Квашнина Ульяна
Uliana1997 Nov 12, 2016
f0e810c
Квашнина Ульяна
Uliana1997 Nov 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 83 additions & 49 deletions lego.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,70 +1,104 @@
'use strict';

/**
* Сделано задание на звездочку
* Реализованы методы or и and
*/
exports.isStar = true;

/**
* Запрос к коллекции
* @param {Array} collection
* @params {...Function} – Функции для запроса
* @returns {Array}
*/
exports.isStar = false;

// Чем больше число тем ниже приоритет функции
var priority = {

@evilj0e evilj0e Nov 9, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Стоит написать комментарий, что значат эти цифры – больше число выполнится "быстрее" или в последнюю очередь

filterIn: 1,
sortBy: 2,
select: 3,
limit: 4,
format: 5
};

exports.query = function (collection) {
return collection;
var newCollection = copyCollection(collection);
var functions = Array.prototype.slice.call(arguments).slice(1);
function compare(one, another) {

@onufrienko onufrienko Nov 4, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Эту функцию можно сильно сократить, возвращая, например, x - y

return priority[one.name] - priority[another.name];
}

@evilj0e evilj0e Nov 9, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Зачем поудаляла все jsdoc?

@Uliana1997 Uliana1997 Nov 9, 2016

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

мне с ними было неудобно, тут маленький код и так было понятно( мне их вернуть назад??

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Их же можно сворачивать в IDE :) В данном случае, да маленький, но стоит привыкать с ним работать. Писать *doc – хороший тон.

functions.sort(compare);

@evilj0e evilj0e Nov 9, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Не старайся усложнять там, где всё можно сделать проще. Когда функция сортировки достаточно простая, не стоит выносить её в отдельную функцию. К тому же её можно написать сильно короче и проще:

functions.sort(function (a, b) {
 return priority[a.name] - priority[b.name];
});

functions.forEach(function (eachQuery) {
newCollection = eachQuery(newCollection);
});

return newCollection;
};

/**
* Выбор полей
* @params {...String}
*/
function copyCollection(collection) {

return (collection.map(function (friend) {

return Object.assign({}, friend);
}));
}

exports.select = function () {
return;
};
var fields = Array.prototype.slice.call(arguments);

/**
* Фильтрация поля по массиву значений
* @param {String} property – Свойство для фильтрации
* @param {Array} values – Доступные значения
*/
exports.filterIn = function (property, values) {
console.info(property, values);
return function select(collection) {

return;
return collection.reduce(function (prev, curr) {
var friend = {};
for (var field in curr) {
if (fields.indexOf(field) !== -1) {
friend[field] = curr[field];
}
}
prev.push(friend);

return prev;
}, []);

};
};

/**
* Сортировка коллекции по полю
* @param {String} property – Свойство для фильтрации
* @param {String} order – Порядок сортировки (asc - по возрастанию; desc – по убыванию)
*/
exports.sortBy = function (property, order) {
console.info(property, order);
return function sortBy(collection) {

@onufrienko onufrienko Nov 4, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

у тебя получилась достаточно большая функция сортировки, ее можно сделать проще

@evilj0e evilj0e Nov 9, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ульяна, у тебя есть идеи как оптимизировать эту функцию?

@Uliana1997 Uliana1997 Nov 9, 2016

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

есть, сейчас я исправлю всё

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍
Супер! Спасибо

function compare(one, another) {
return (one[property] > another[property]) ? 1 : -1;
}

return;
if (order === 'asc') {
collection.sort(compare);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Метод sort – не чистая функция. Только что ты мутировала коллекцию. Требования задания не учтены.

} else {
collection.sort(compare).reverse();
}

return collection;
};
};

/**
* Форматирование поля
* @param {String} property – Свойство для фильтрации
* @param {Function} formatter – Функция для форматирования
*/
exports.format = function (property, formatter) {
console.info(property, formatter);
exports.limit = function (count) {
return function limit(collection) {
return collection.slice(0, count);
};
};

return;
exports.filterIn = function (property, values) {
return function filterIn(collection) {

@onufrienko onufrienko Nov 4, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

попробуй метод filter

var newSorted = [];
collection.forEach(function (friend) {
for (var field in friend) {
if (property === field.toString() &&
values.indexOf(friend[field]) !== -1) {
newSorted.push(Object.assign({}, friend));
}
}
});

return newSorted;
};
};

/**
* Ограничение количества элементов в коллекции
* @param {Number} count – Максимальное количество элементов
*/
exports.limit = function (count) {
console.info(count);
exports.format = function (property, formatter) {
return function format(collection) {
return collection.map(function (friend) {
friend[property] = formatter(friend[property]);

return;
return friend;
});
};
};

if (exports.isStar) {
Expand Down

AltStyle によって変換されたページ (->オリジナル) /