diff --git a/03-objects-arrays-intro-to-testing/1-create-getter/index.js b/03-objects-arrays-intro-to-testing/1-create-getter/index.js index c86ac40..9e9ac0c 100644 --- a/03-objects-arrays-intro-to-testing/1-create-getter/index.js +++ b/03-objects-arrays-intro-to-testing/1-create-getter/index.js @@ -4,5 +4,11 @@ * @returns {function} - function-getter which allow get value from object by set path */ export function createGetter(path) { - + const arr = path.split('.'); + + return function(obj) { + return arr.reduce((accum, item)=> + accum.hasOwnProperty(item) ? accum[item] : undefined, obj) + + } } diff --git a/03-objects-arrays-intro-to-testing/2-invert-object/index.js b/03-objects-arrays-intro-to-testing/2-invert-object/index.js index d6f6b7c..8ed6089 100644 --- a/03-objects-arrays-intro-to-testing/2-invert-object/index.js +++ b/03-objects-arrays-intro-to-testing/2-invert-object/index.js @@ -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])); } diff --git a/03-objects-arrays-intro-to-testing/3-trim-symbols/index.js b/03-objects-arrays-intro-to-testing/3-trim-symbols/index.js index bdafd72..e08ba6a 100644 --- a/03-objects-arrays-intro-to-testing/3-trim-symbols/index.js +++ b/03-objects-arrays-intro-to-testing/3-trim-symbols/index.js @@ -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; } diff --git a/03-objects-arrays-intro-to-testing/4-uniq/index.js b/03-objects-arrays-intro-to-testing/4-uniq/index.js index b81423b..fa6cce3 100644 --- a/03-objects-arrays-intro-to-testing/4-uniq/index.js +++ b/03-objects-arrays-intro-to-testing/4-uniq/index.js @@ -4,5 +4,5 @@ * @returns {*[]} - the new array with uniq values */ export function uniq(arr) { - + return Array.from(new Set(arr)); }