Skip to content

Commit adaae70

Browse files
authored
Merge pull request #4 from osvetilka/master
задача 3.1 не доделана, не проходит 1 тест. задачи 3.2-3.3 выполнены
2 parents 1942adc + b179882 commit adaae70

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

03-objects-arrays-intro-to-testing/1-create-getter/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,12 @@
44
* @returns {function} - function-getter which allow get value from object by set path
55
*/
66
export function createGetter(path) {
7-
7+
const arr = path.split('.');
8+
9+
return function(obj) {
10+
if (!obj.hasOwnProperty(arr[0])) return ;
11+
return arr.reduce((accum, item)=>
12+
accum.hasOwnProperty(item) ? accum[item] : undefined, obj)
13+
14+
}
815
}

03-objects-arrays-intro-to-testing/2-invert-object/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
* @returns {object | undefined} - returns new object or undefined if nothing did't pass
55
*/
66
export function invertObj(obj) {
7+
if (obj === undefined)
8+
return;
79

10+
const arr = Object.entries(obj);
11+
return Object.fromEntries(arr.map(([keys,values])=>[values,keys]));
812
}

03-objects-arrays-intro-to-testing/3-trim-symbols/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,20 @@
55
* @returns {string} - the new string without extra symbols according passed size
66
*/
77
export function trimSymbols(string, size) {
8+
if (string==='' || size === 0) return '';
9+
if (size === undefined) return string;
810

11+
let newStr = '';
12+
let n = 1;
13+
for (let i = 0; i < string.length; i++) {
14+
if (string[i] === string[i-1]) {
15+
n++;
16+
}
17+
else n = 1;
18+
19+
if (n <= size) {
20+
newStr = newStr + string[i];
21+
}
22+
}
23+
return newStr;
924
}

03-objects-arrays-intro-to-testing/4-uniq/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* @returns {*[]} - the new array with uniq values
55
*/
66
export function uniq(arr) {
7-
7+
return Array.from(new Set(arr));
88
}

0 commit comments

Comments
 (0)