Skip to content

Commit b7eb8df

Browse files
authored
Merge pull request #3 from osvetilka/master
Задача 2.1 доработка, Задача 2.2
2 parents 4d34923 + 90f4291 commit b7eb8df

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

02-javascript-data-types/1-sort-strings/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
* @returns {string[]}
66
*/
77
export function sortStrings(arr, param = 'asc') {
8-
let sortArr = [...arr];
9-
8+
const sortArr = [...arr];
9+
1010
if (param === 'asc') {
1111
return sortArr.sort((a, b) => a.localeCompare(b,'ru',{caseFirst: 'upper'}));
1212
}
13-
else if (param === 'desc') {
14-
return sortArr.sort((a, b) => -a.localeCompare(b,'ru',{caseFirst: 'upper'}));
15-
}
13+
14+
return sortArr.sort((a, b) => -a.localeCompare(b,'ru',{caseFirst: 'upper'}));
1615
}
1716

02-javascript-data-types/2-pick/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @param {...string} fields - the properties paths to pick
55
* @returns {object} - returns the new object
66
*/
7-
export const pick = (obj, ...fields) => {
8-
7+
export const pick = (obj, ...fields) => {
8+
const filt = Object.entries(obj).filter(item => fields.includes(item[0]))
9+
return Object.fromEntries(filt);
910
};

02-javascript-data-types/3-omit/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
* @returns {object} - returns the new object
66
*/
77
export const omit = (obj, ...fields) => {
8-
8+
const filt = Object.entries(obj).filter(item => !fields.includes(item[0]))
9+
return Object.fromEntries(filt);
910
};

0 commit comments

Comments
 (0)