forked from fac-17/fac17-projects-gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.js
37 lines (30 loc) · 787 Bytes
/
logic.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
console.log("logic.js")
// provide data for the app
const getData = ()=>{
// sort weeks so they start from latest
data.weeks=data.weeks.sort( (w1,w2)=>w2.week-w1.week );
// randomize the order of projects in a week
data.weeks=data.weeks.map(week=>{
week.projects=shuffleArray(week.projects)
.map(project=>{
project.team=shuffleArray(project.team);
return project;
})
return week;
})
return data;
}
const randomInt=(max)=>{
return Math.floor(Math.random()*max);
}
const shuffleArray=(array)=>{
const newArr=[];
const arr=array.slice();
while (arr.length){
newArr.push(arr.splice(randomInt(arr.length),1)[0]);
}
return newArr;
}
const logic={
getData
}