-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers.js
60 lines (58 loc) · 1.68 KB
/
helpers.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function printAllInConsole(arr, type) {
if (type === "onlyQ") {
arr.forEach((element, index) => {
console.log(`Q.${index+1}`, JSON.stringify(element,undefined,2))
console.log("")
console.log("------------------------------------------")
});
} else if (type === "qWithO") {
arr.forEach((element, index) => {
console.log(`Q.${index+1}`, JSON.stringify(element.q,undefined,2))
element.ops.forEach((el, index) => {
const letter = String.fromCharCode(index + 97)
console.log(`${letter}) `,el)
})
console.log("")
console.log("------------------------------------------")
});
} else {
console.log("The array you passed is,", JSON.stringify(arr, undefined, 2))
console.log("Invalid type passed")
console.log("The types are:")
console.log("onlyQs -----> When the array has only Questions");
console.log("qWithO -----> When the array passed has Questions and options")
}
}
/*
[
{
q:'',
ops: [
{
op: "",
upvo: 11,
dovot: 0,
}
]
}
]
*/
function convertArrytoIncVotes (arr) {
const initialArray = arr;
let qOV = [];
qOV = initialArray.map(qObj => {
let options = []
options = qObj.ops.forEach(opt => {
return {
option: opt,
upVotes: 0,
downVotes: 0,
}
})
return {
q: qObj.q,
ops: options
}
})
}
module.exports = {printAllInConsole, convertArrytoIncVotes}