This repository was archived by the owner on Jul 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (41 loc) · 1.48 KB
/
index.js
File metadata and controls
49 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(function(module) {
"use strict";
var Category = module.parent.require('./categories');
var _ = module.parent.require('underscore');
var async = module.parent.require('async');
var _OJ_CATEGORY_ID = 8;
var _INTERVIEW_QUESTION_CID = 5;
var Leetcode = {};
Leetcode.createCategory = function (data, next) {
if ('_imported_parentCid' in data['data']) {
data['category']['_imported_parentCid'] = data['data']['_imported_parentCid'];
}
if ('_imported_slug' in data['data']) {
data['category']['_imported_slug'] = data['data']['_imported_slug'];
}
next(null, data);
}
Leetcode.getCategoryTopic = function (data, next) {
var cids = _.uniq(_.map(data.topics, function (obj, index){
return obj.category.cid;
}));
Category.getCategoriesFields(cids, ['cid', 'parentCid', 'image'], function (err, categories){
var cid_parentCid_map = {};
for (var i = 0; i < categories.length; ++i) {
cid_parentCid_map[categories[i].cid] = categories[i];
}
for (i = 0; i < data.topics.length; ++i){
var topic = data.topics[i];
topic.showCategoryIconForTopics = false;
if (cid_parentCid_map[topic.category.cid].parentCid == _INTERVIEW_QUESTION_CID
&& data.cid == _INTERVIEW_QUESTION_CID) {
topic.showCategoryIconForTopics = true;
topic.category.parentCid = cid_parentCid_map[topic.category.cid].parentCid;
topic.category.image = cid_parentCid_map[topic.category.cid].image;
}
}
next(null, data);
});
}
module.exports = Leetcode;
}(module));