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

задача 3.1 не доделана, не проходит 1 тест. задачи 3.2-3.3 выполнены #4

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion 03-objects-arrays-intro-to-testing/1-create-getter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@
* @returns {function} - function-getter which allow get value from object by set path
*/
export function createGetter(path) {

const arr = path.split('.');

return function(obj) {
if (!obj.hasOwnProperty(arr[0])) return ;
Copy link

Choose a reason for hiding this comment

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

Почему проверка идет только для первого элемента? Кажется что это условие можно опустить, у вас ниже похожая работа но в reduce

Copy link

Choose a reason for hiding this comment

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

Попробуйте избавиться от этой строки

return arr.reduce((accum, item)=>
accum.hasOwnProperty(item) ? accum[item] : undefined, obj)

}
}
4 changes: 4 additions & 0 deletions 03-objects-arrays-intro-to-testing/2-invert-object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
* @returns {object | undefined} - returns new object or undefined if nothing did't pass
*/
export function invertObj(obj) {
if (obj === undefined)
Copy link

Choose a reason for hiding this comment

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

if (!obj) {
 return;
}

return;

const arr = Object.entries(obj);
return Object.fromEntries(arr.map(([keys,values])=>[values,keys]));
Copy link

Choose a reason for hiding this comment

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

опечатка? [key, value]

}
15 changes: 15 additions & 0 deletions 03-objects-arrays-intro-to-testing/3-trim-symbols/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,20 @@
* @returns {string} - the new string without extra symbols according passed size
*/
export function trimSymbols(string, size) {
if (string==='' || size === 0) return '';
if (size === undefined) return string;

let newStr = '';
let n = 1;
for (let i = 0; i < string.length; i++) {
if (string[i] === string[i-1]) {
n++;
}
else n = 1;
Copy link

Choose a reason for hiding this comment

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

лучше не опускать скобки в if/else для повышения читаемости


if (n <= size) {
newStr = newStr + string[i];
}
}
return newStr;
}
2 changes: 1 addition & 1 deletion 03-objects-arrays-intro-to-testing/4-uniq/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* @returns {*[]} - the new array with uniq values
*/
export function uniq(arr) {

return Array.from(new Set(arr));
}