Guest User

Untitled

a guest
Nov 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. const excluded = []; // LOW skilled
  2. const reserves = []; // only MEDIUM/HIGH skilled
  3. const team = []; // only HIGH skilled
  4.  
  5. const allPlayers = [
  6. {
  7. name: 'personh1',
  8. skillLevel: 'HIGH'
  9. },
  10. {
  11. name: 'personh2',
  12. skillLevel: 'HIGH'
  13. },
  14. {
  15. name: 'personh3',
  16. skillLevel: 'HIGH'
  17. },
  18. {
  19. name: 'personm1',
  20. skillLevel: 'MEDIUM'
  21. },
  22. {
  23. name: 'personm2',
  24. skillLevel: 'MEDIUM'
  25. },
  26. {
  27. name: 'personl1',
  28. skillLevel: 'LOW'
  29. },
  30. {
  31. name: 'personl2',
  32. skillLevel: 'LOW'
  33. }
  34. ];
  35.  
  36. const maxTeamSize = 2;
  37. const maxReservesSize = 2;
  38.  
  39. allPlayers.forEach(p => {
  40. if (p.skillLevel === 'HIGH') {
  41. if (team.length < maxTeamSize) {
  42. team.push(p);
  43. } else {
  44. reserves.push(p);
  45. }
  46. } else if (p.skillLevel === 'MEDIUM') {
  47. if (reserves.length < maxReservesSize) {
  48. reserves.push(p);
  49. } else {
  50. excluded.push(p);
  51. }
  52. } else {
  53. excluded.push(p);
  54. }
  55. });
  56.  
  57. // functions defined elsewhere...
  58. notifyOfInclusion(team.concat(reserves));
  59. notifyOfExclusion(excluded);
  60.  
  61. team = R.slice(0, maxTeamSize, R.filter(p => p.skillLevel === 'HIGH', allPlayers));
  62. reserves = R.slice(0, maxReservesSize, R.filter(p => (p.skillLevel === 'HIGH' || p.skillLevel === 'MEDIUM') && !R.contains(p, team), allPlayers));
  63. excluded = R.filter(p => !R.contains(p, team) && !R.contains(p, reserves), allPlayers);
  64.  
  65. notifyOfInclusion(team.concat(reserves));
  66. notifyOfExclusion(excluded);
Add Comment
Please, Sign In to add comment