-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
35 lines (27 loc) · 1.04 KB
/
utils.js
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
const fs = require("fs"),
_ = require("lodash");
const q = require("./questions.json");
const groupBy = _.curryRight(_.groupBy);
const groupByCategory = groupBy((q) => q.category);
function generateQuestions(numCategories, numQuestions) {
const qByCategory = groupByCategory(q);
let response = `# Random 1 on 1 Questions
👋🏻 Hiya! This is a randomly picked selection of 1 on 1 questions (from a total of ${q.length}), dived by category. Feel free to use whatever is most relevant and only if it makese sense!`;
const flattened = _.flatten(_.sampleSize(qByCategory, numCategories));
const randomCategories = groupByCategory(flattened);
const qs = _.reduce(
randomCategories,
function (memo, curr) {
const rq = _.sampleSize(curr, numQuestions);
return _.concat(memo, rq);
},
[]
);
_.each(groupByCategory(qs), (q, c) => {
let r = `\n\n## ${c}\n`;
r += q.map((curr) => `- ${curr.question}`).join("\n");
response += r;
});
return response;
}
exports.generateQuestions = generateQuestions;