Skip to content

Commit 4f94db9

Browse files
committed
refactor even more
1 parent 110d5cc commit 4f94db9

64 files changed

Lines changed: 642 additions & 269 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compare-solution.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@ module.exports = function(solution, attempt, cb) {
2626
return cb(true);
2727
}
2828

29-
console.error("\nSolution:\n------------------------");
30-
console.error(solutionResult);
31-
console.error("Your attempt:\n------------------------");
32-
console.error(attemptResult);
33-
console.error("Difference:\n------------------------");
34-
console.error(generateDiff(solutionResult, attemptResult));
35-
36-
cb(false);
29+
cb(false, {
30+
solution: solutionResult,
31+
attempt: attemptResult,
32+
diff: generateDiff(solutionResult, attemptResult)
33+
});
3734

3835
});
3936

problems/array-filtering/index.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,41 @@ var path = require('path');
22
var getFile = require('../../get-file');
33
var compare = require('../../compare-solution');
44

5-
exports.problem = getFile(path.join(__dirname, 'problem.md'));
5+
var problemName = __dirname.split('/');
6+
problemName = problemName[problemName.length-1];
67

8+
exports.problem = getFile(path.join(__dirname, 'problem.md'));
79
exports.solution = getFile(path.join(__dirname, 'solution.md'));
810

9-
exports.fail = getFile(path.join(__dirname, 'troubleshooting.md'));
10-
11-
var solutionPath = path.resolve(__dirname, "../../solutions/array-filtering/index.js");
11+
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js");
12+
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md");
1213

1314
exports.verify = function (args, cb) {
15+
1416
var attemptPath = path.resolve(process.cwd(), args[0]);
15-
compare(solutionPath, attemptPath, cb);
17+
compare(solutionPath, attemptPath, function(match, obj) {
18+
19+
if(match) {
20+
return cb(true);
21+
}
22+
23+
if(!obj) {
24+
// An error occured, we've already printed an error
25+
return;
26+
}
27+
28+
var message = getFile(troubleshootingPath);
29+
30+
message = message.replace(/%solution%/g, obj.solution);
31+
message = message.replace(/%attempt%/g, obj.attempt);
32+
message = message.replace(/%diff%/g, obj.diff);
33+
message = message.replace(/%filename%/g, args[0]);
34+
35+
exports.fail = message;
36+
37+
cb(false);
38+
39+
});
1640
};
1741

1842
exports.run = function (args) {

problems/array-filtering/readme.md

Whitespace-only changes.

problems/array-filtering/troubleshooting.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

problems/arrays/index.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,41 @@ var path = require('path');
22
var getFile = require('../../get-file');
33
var compare = require('../../compare-solution');
44

5-
exports.problem = getFile(path.join(__dirname, 'problem.md'));
5+
var problemName = __dirname.split('/');
6+
problemName = problemName[problemName.length-1];
67

8+
exports.problem = getFile(path.join(__dirname, 'problem.md'));
79
exports.solution = getFile(path.join(__dirname, 'solution.md'));
810

9-
exports.fail = getFile(path.join(__dirname, 'troubleshooting.md'));
10-
11-
var solutionPath = path.resolve(__dirname, "../../solutions/arrays/index.js");
11+
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js");
12+
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md");
1213

1314
exports.verify = function (args, cb) {
15+
1416
var attemptPath = path.resolve(process.cwd(), args[0]);
15-
compare(solutionPath, attemptPath, cb);
17+
compare(solutionPath, attemptPath, function(match, obj) {
18+
19+
if(match) {
20+
return cb(true);
21+
}
22+
23+
if(!obj) {
24+
// An error occured, we've already printed an error
25+
return;
26+
}
27+
28+
var message = getFile(troubleshootingPath);
29+
30+
message = message.replace(/%solution%/g, obj.solution);
31+
message = message.replace(/%attempt%/g, obj.attempt);
32+
message = message.replace(/%diff%/g, obj.diff);
33+
message = message.replace(/%filename%/g, args[0]);
34+
35+
exports.fail = message;
36+
37+
cb(false);
38+
39+
});
1640
};
1741

1842
exports.run = function (args) {

problems/arrays/readme.md

Whitespace-only changes.

problems/arrays/troubleshooting.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

problems/for-loop/index.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,41 @@ var path = require('path');
22
var getFile = require('../../get-file');
33
var compare = require('../../compare-solution');
44

5-
exports.problem = getFile(path.join(__dirname, 'problem.md'));
5+
var problemName = __dirname.split('/');
6+
problemName = problemName[problemName.length-1];
67

8+
exports.problem = getFile(path.join(__dirname, 'problem.md'));
79
exports.solution = getFile(path.join(__dirname, 'solution.md'));
810

9-
exports.fail = getFile(path.join(__dirname, 'troubleshooting.md'));
10-
11-
var solutionPath = path.resolve(__dirname, "../../solutions/for-loop/index.js");
11+
var solutionPath = path.resolve(__dirname, "../../solutions", problemName, "index.js");
12+
var troubleshootingPath = path.resolve(__dirname, "../../troubleshooting.md");
1213

1314
exports.verify = function (args, cb) {
15+
1416
var attemptPath = path.resolve(process.cwd(), args[0]);
15-
compare(solutionPath, attemptPath, cb);
17+
compare(solutionPath, attemptPath, function(match, obj) {
18+
19+
if(match) {
20+
return cb(true);
21+
}
22+
23+
if(!obj) {
24+
// An error occured, we've already printed an error
25+
return;
26+
}
27+
28+
var message = getFile(troubleshootingPath);
29+
30+
message = message.replace(/%solution%/g, obj.solution);
31+
message = message.replace(/%attempt%/g, obj.attempt);
32+
message = message.replace(/%diff%/g, obj.diff);
33+
message = message.replace(/%filename%/g, args[0]);
34+
35+
exports.fail = message;
36+
37+
cb(false);
38+
39+
});
1640
};
1741

1842
exports.run = function (args) {

problems/for-loop/readme.md

Whitespace-only changes.

problems/for-loop/troubleshooting.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)