Skip to content

Commit a7bcb76

Browse files
committed
Merge remote-tracking branch 'AB/master'
add A new solution for a new condition
2 parents 9c49ef4 + bdd0828 commit a7bcb76

18 files changed

Lines changed: 1197 additions & 528 deletions

README.md

Lines changed: 298 additions & 239 deletions
Large diffs are not rendered by default.

README_RU.md

Lines changed: 299 additions & 0 deletions
Large diffs are not rendered by default.

extensions/custom-error.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const CustomError = class CustomError extends Error {
2+
constructor(message) {
3+
super(message);
4+
this._validationProp = 'NA';
5+
}
6+
};
7+
8+
module.exports = CustomError;

extensions/it-optional.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
// code from https://github.com/mikhama/core-js-101
1+
// code is based on solution from https://github.com/mikhama/core-js-101
22
function testOptional(title, fn, isAsyncTest) {
33
if (isAsyncTest) {
44
it(title, function test(done) {
55
try {
66
fn.call(this, done);
77
} catch (err) {
8-
if (err === 'Not implemented') {
9-
console.log('NOT IMPLEMENTED' + title);
8+
if (err._validationProp === 'NA') {
109
this.test.skip();
1110
} else {
12-
console.log('ERR UP' + title);
1311
throw err;
1412
}
1513
}
@@ -19,7 +17,7 @@ function testOptional(title, fn, isAsyncTest) {
1917
try {
2018
fn.call(this);
2119
} catch (err) {
22-
if (err === 'Not implemented') {
20+
if (err._validationProp === 'NA') {
2321
this.test.skip();
2422
} else {
2523
throw err;

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dream-team.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
const CONSOLE_LOG_ENABLE = false;
22

33
module.exports = function createDreamTeam(members_array/* members */) {
4-
if (!(Array.isArray(members_array))){
5-
if (CONSOLE_LOG_ENABLE) console.log ((Array.isArray(members_array)));
4+
if (!(Array.isArray(members_array))) {
5+
if (CONSOLE_LOG_ENABLE) console.log((Array.isArray(members_array)));
66
return false;
77
}
88

99
let team = '';
1010

11-
for (let i = 0; i<members_array.length; i++) {
12-
if (typeof( members_array[i] ) === "string"){
13-
team += members_array[i].match(/\w/);
11+
for (let i = 0; i < members_array.length; i++) {
12+
if (typeof (members_array[i]) === "string") {
13+
team += members_array[i].match(/\w/);
1414
}
1515
}
1616

17-
if (CONSOLE_LOG_ENABLE) console.log(team);
17+
if (CONSOLE_LOG_ENABLE) console.log(team);
1818
team = team.toUpperCase().split("").sort().join("");
19-
if (CONSOLE_LOG_ENABLE) console.log(team);
19+
if (CONSOLE_LOG_ENABLE) console.log(team);
2020

2121
if (team === "") {
2222
return false;
2323
}
2424
return team;
2525
// throw 'Not implemented';
2626
// // remove line with error and write your code here
27-
};
27+
};

src/extended-repeater.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ module.exports = function repeater(str, options) {
2626
outstring = outstring + str + add_str;
2727
} while (i < repeatTimes);
2828
return outstring;
29-
throw 'Not implemented';
3029
// remove line with error and write your code here
3130
};

src/hanoi-tower.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module.exports = function calculateHanoi( disksNumber, turnsSpeed ) {
77
for(let i=1; i<=disksNumber;i++){
88
obj.turns = obj.turns*2 +1;
99
}
10-
obj.seconds = obj.turns/ (turnsSpeed/ 3600);
10+
// console.log('myseconds',obj.turns * 3600 / turnsSpeed);
11+
obj.seconds = Math.floor(obj.turns * 3600 / turnsSpeed);
12+
// console.log('myseconds',obj.seconds);
1113
return obj;
12-
}
14+
}

src/recursive-depth.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const CustomError = require("../extensions/custom-error");
2+
13
module.exports = class DepthCalculator {
24
calculateDepth(arr) {
35
// console.log (arr)

src/transform-array.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function transform(inc_arr) {
1313
}
1414
if (SHOW_CONSOLE_LOG) console.log('start program');
1515
if (SHOW_CONSOLE_LOG) console.log('array length', inc_arr.length, 'array:', inc_arr);
16-
16+
/* Я так понимаю задачу упростили, плак плак плак плак ...
1717
1818
for (let i = 0; i < inc_arr.length; i++) {
1919
if (inc_arr[i] in CONTROLS) {
@@ -61,11 +61,51 @@ module.exports = function transform(inc_arr) {
6161
}
6262
}
6363
}
64-
65-
66-
6764
if (SHOW_CONSOLE_LOG) console.log('array length', inc_arr.length, 'array:', inc_arr);
6865
if (SHOW_CONSOLE_LOG) console.log('end program');
69-
return inc_arr;
66+
*/
67+
68+
let myArr = inc_arr.slice();
69+
for (let i = 0; i < myArr.length; i++) {
70+
if (myArr[i] in CONTROLS) {
71+
switch (myArr[i]) {
72+
case '--double-prev':
73+
if (i > 0) {
74+
myArr[i] = myArr[i-1];
75+
} else {
76+
myArr[i] = null;
77+
}
78+
break;
79+
case '--double-next':
80+
if ((i+1) < inc_arr.length) {
81+
myArr[i] = myArr[i+1];
82+
} else {
83+
myArr[i] = null;
84+
}
85+
break;
86+
case '--discard-prev':
87+
if (i > 0) {
88+
myArr[i] = null;
89+
myArr[i-1] = null;
90+
} else {
91+
myArr[i] = null;
92+
}
93+
break;
94+
case '--discard-next':
95+
if (i < (inc_arr.length - 1)) {
96+
myArr[i] = null;
97+
myArr[i+1] = null;
98+
} else {
99+
myArr[i] = null;
100+
}
101+
i++;
102+
break;
103+
}
104+
}
105+
}
106+
myArr = myArr.filter((el) => el !== null);
107+
if (SHOW_CONSOLE_LOG) console.log('array length', myArr.length, 'array:', myArr);
108+
if (SHOW_CONSOLE_LOG) console.log('end program');
109+
return myArr;
70110
// remove line with error and write your code here
71111
};

0 commit comments

Comments
 (0)