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

решение задач 2 модуля #2

Merged
merged 11 commits into from
Jan 26, 2025
8 changes: 8 additions & 0 deletions 02-javascript-data-types/1-sort-strings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@
* @returns {string[]}
*/
export function sortStrings(arr, param = 'asc') {
const newArr = arr.slice();

if (param == 'asc') {
newArr.sort((a, b) => a.localeCompare(b, ['ru-RU', 'en-US', 'en-GB'], {caseFirst: 'upper'}));
} else if (param == 'desc') {
newArr.sort((a, b) => b.localeCompare(a, ['ru-RU', 'en-US', 'en-GB'], {caseFirst: 'lower'}));
}

return newArr;
}
4 changes: 4 additions & 0 deletions 02-javascript-data-types/2-pick/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
* @returns {object} - returns the new object
*/
export const pick = (obj, ...fields) => {
const result = {};

fields.map((item) => result[item] = obj[item]);

Choose a reason for hiding this comment

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

Не используйте map, используйте forEach или другой способ обхода массива


return result;
};
4 changes: 4 additions & 0 deletions 02-javascript-data-types/3-omit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
* @returns {object} - returns the new object
*/
export const omit = (obj, ...fields) => {
const newObj = obj;

fields.map((item) => delete newObj[item]);

Choose a reason for hiding this comment

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

Не используйте map, используйте forEach или другой способ обхода массива


return newObj;
};
Loading