-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewShuffler.js
28 lines (28 loc) · 1.06 KB
/
viewShuffler.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
module.exports = function(allCommentData, recursive=false){
let orderedComments = [];
const sortedComments = allCommentData.sort((a,b) => a.get("politicization_index") - b.get("politicization_index"));
let polList=[];
for (let x of sortedComments){
polList.push(x.get("politicization_index"));
}
while (polList.length >= 4){
var index = polList.length;
var sml = Math.floor(polList.length / 4);
var grouping = [];
for (const x of Array(4).keys()){
index -= sml;
var targetdel = index + Math.floor(sml * Math.random());
grouping.push(sortedComments[targetdel]);
sortedComments.splice(targetdel,1);
}
polList=[];
for (let x of sortedComments){
polList.push(x.get("politicization_index"));
}
var shuffled = grouping;
const shuffledArray = shuffled.sort((a,b) => 0.5 - Math.random());
orderedComments.push(...shuffledArray);
}
orderedComments.push(...sortedComments);
return orderedComments;
}