Skip to content

Commit

Permalink
Merge pull request #4 from osvetilka/master
Browse files Browse the repository at this point in the history
задача 3.1 не доделана, не проходит 1 тест. задачи 3.2-3.3 выполнены
  • Loading branch information
jsru-1 authored Feb 5, 2025
2 parents 1942adc + b179882 commit adaae70
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
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 ;
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)
return;

const arr = Object.entries(obj);
return Object.fromEntries(arr.map(([keys,values])=>[values,keys]));
}
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;

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));
}

0 comments on commit adaae70

Please sign in to comment.