Skip to content

Commit

Permalink
Merge pull request #3 from osvetilka/master
Browse files Browse the repository at this point in the history
Задача 2.1 доработка, Задача 2.2
  • Loading branch information
jsru-1 authored Jan 30, 2025
2 parents 4d34923 + 90f4291 commit b7eb8df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
9 changes: 4 additions & 5 deletions 02-javascript-data-types/1-sort-strings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* @returns {string[]}
*/
export function sortStrings(arr, param = 'asc') {
let sortArr = [...arr];
const sortArr = [...arr];

if (param === 'asc') {
return sortArr.sort((a, b) => a.localeCompare(b,'ru',{caseFirst: 'upper'}));
}
else if (param === 'desc') {
return sortArr.sort((a, b) => -a.localeCompare(b,'ru',{caseFirst: 'upper'}));
}

return sortArr.sort((a, b) => -a.localeCompare(b,'ru',{caseFirst: 'upper'}));
}

5 changes: 3 additions & 2 deletions 02-javascript-data-types/2-pick/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @param {...string} fields - the properties paths to pick
* @returns {object} - returns the new object
*/
export const pick = (obj, ...fields) => {

export const pick = (obj, ...fields) => {
const filt = Object.entries(obj).filter(item => fields.includes(item[0]))
return Object.fromEntries(filt);
};
3 changes: 2 additions & 1 deletion 02-javascript-data-types/3-omit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
* @returns {object} - returns the new object
*/
export const omit = (obj, ...fields) => {

const filt = Object.entries(obj).filter(item => !fields.includes(item[0]))
return Object.fromEntries(filt);
};

0 comments on commit b7eb8df

Please sign in to comment.