summaryrefslogtreecommitdiffstats
path: root/lib/parse/is_exercise.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parse/is_exercise.js')
-rw-r--r--lib/parse/is_exercise.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/parse/is_exercise.js b/lib/parse/is_exercise.js
new file mode 100644
index 0000000..74ed753
--- /dev/null
+++ b/lib/parse/is_exercise.js
@@ -0,0 +1,17 @@
+var _ = require('lodash');
+
+function isExercise(nodes) {
+ var codeType = { type: 'code' };
+
+ // Number of code nodes in section
+ var len = _.filter(nodes, codeType).length;
+
+ return (
+ // Got 3 or 4 code blocks
+ (len === 3 || len === 4) &&
+ // Ensure all nodes are at the end
+ _.all(_.last(nodes, len), codeType)
+ );
+}
+
+module.exports = isExercise;