Skip to content

Commit

Permalink
chore: revert generate.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Chersquwn committed Apr 18, 2019
1 parent 6cd5a18 commit d61ddef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,11 @@ LeetCode solutions with JavaScript
| 107 | [Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii/) | | | Easy |
| 106 | [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | | | Medium |
| 105 | [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | | | Medium |
| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | | | Easy |
| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | | [JavaScript](./algorithms/Maximum%20Depth%20of%20Binary%20Tree/index.js) | Easy |
| 103 | [Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/) | | | Medium |
| 102 | [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/) | | | Medium |
| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | | | Easy |
| 100 | [Same Tree](https://leetcode.com/problems/same-tree/) | | | Easy |
| 100 | [Same Tree](https://leetcode.com/problems/same-tree/) | | [JavaScript](./algorithms/Same%20Tree/index.js) | Easy |
| 99 | [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree/) | | | Hard |
| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/) | | | Medium |
| 97 | [Interleaving String](https://leetcode.com/problems/interleaving-string/) | | | Hard |
Expand Down
23 changes: 3 additions & 20 deletions scripts/generate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const axios = require('axios');
const fs = require('fs');

const EXPIRED = 30 * 24 * 60 * 60
const API = 'https://leetcode.com/api/problems/algorithms/';
const SOLUTION_Path = './algorithms/';
let README_TMPL = `# LeetCode
Expand All @@ -14,29 +13,17 @@ LeetCode solutions with JavaScript
|:---:|:---:|:---:|:---:|:---:|
`;

getProblems()
fetchProblems()
.then(problems => {
return addSolutions(problems);
})
.then(problems => {
// generateReadme(problems);
generateReadme(problems);
});

function getProblems() {
try {
const stats = fs.statSync('../.cache/problem.js')

if (new Date() - new Date(stats.mtime) > EXPIRED) {
return fetchProblems()
}

return require('../.cache/problem')
} catch (error) {
return fetchProblems()
}
}

function fetchProblems() {
const time = Date.now()
return axios.get(API).then(res => {
const { stat_status_pairs } = res.data;
const difficulty = ['', 'Easy', 'Medium', 'Hard'];
Expand All @@ -48,10 +35,6 @@ function fetchProblems() {
difficulty: difficulty[item.difficulty.level]
}))
.sort((a, b) => b.id - a.id);

fs.mkdirSync('../.cache')
fs.writeFileSync('../.cache/problem.js', problems)

return problems;
});
}
Expand Down

0 comments on commit d61ddef

Please sign in to comment.