Skip to content

Commit 7d6d021

Browse files
Vigilansjdneo
authored andcommitted
Add likes and dislikes property to problem description (#3)
1 parent 275e502 commit 7d6d021

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

lib/commands/show.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,20 @@ function showProblem(problem, argv) {
152152
log.printf('* %s', problem.category);
153153
log.printf('* %s (%s%%)', h.prettyLevel(problem.level), problem.percent.toFixed(2));
154154

155-
if (filename)
156-
log.printf('* Source Code: %s', chalk.yellow.underline(filename));
155+
if (problem.likes)
156+
log.printf('* Likes: %s', problem.likes);
157+
if (problem.dislikes)
158+
log.printf('* Dislikes: %s', problem.dislikes);
159+
else
160+
log.printf('* Dislikes: -');
157161
if (problem.totalAC)
158162
log.printf('* Total Accepted: %s', problem.totalAC);
159163
if (problem.totalSubmit)
160164
log.printf('* Total Submissions: %s', problem.totalSubmit);
161165
if (problem.testable && problem.testcase)
162166
log.printf('* Testcase Example: %s', chalk.yellow(util.inspect(problem.testcase)));
167+
if (filename)
168+
log.printf('* Source Code: %s', chalk.yellow.underline(filename));
163169

164170
log.info();
165171
log.info(problem.desc);

lib/plugins/cache.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@ plugin.getProblem = function(problem, cb) {
2828
const k = h.KEYS.problem(problem);
2929
const _problem = cache.get(k);
3030
if (_problem) {
31-
// Only hit description with html tags (<pre> always exists for presenting testcase)
32-
if (_problem.desc.includes("<pre>")) {
31+
// do not hit problem without html tags in desc (<pre> always exists for presenting testcase)
32+
if (!_problem.desc.includes("<pre>")) {
33+
log.debug('cache discarded for being no longer valid: ' + k + '.json');
34+
}
35+
// do not hit problem without likes & dislikes (logic will be improved in new lib)
36+
else if (!['likes', 'dislikes'].every(p => p in _problem)) {
37+
log.debug('cache discarded for being too old: ' + k + '.json');
38+
}
39+
// cache hit
40+
else {
3341
log.debug('cache hit: ' + k + '.json');
3442
_.extendOwn(problem, _problem);
3543
return cb(null, problem);
3644
}
37-
log.debug('cache discarded for being no longer valid: ' + k + '.json');
3845
}
3946

4047
plugin.next.getProblem(problem, function(e, _problem) {

lib/plugins/leetcode.js

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ plugin.getProblem = function(problem, cb) {
134134
' question(titleSlug: $titleSlug) {',
135135
' content',
136136
' stats',
137+
' likes',
138+
' dislikes',
137139
' codeDefinition',
138140
' sampleTestCase',
139141
' enableRunCode',
@@ -157,6 +159,8 @@ plugin.getProblem = function(problem, cb) {
157159

158160
problem.totalAC = JSON.parse(q.stats).totalAccepted;
159161
problem.totalSubmit = JSON.parse(q.stats).totalSubmission;
162+
problem.likes = q.likes;
163+
problem.dislikes = q.dislikes;
160164

161165
const content = q.translatedContent ? q.translatedContent : q.content;
162166
// // Replace <sup/> with '^' as the power operator

0 commit comments

Comments
 (0)