Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const excluded = []; // LOW skilled
- const reserves = []; // only MEDIUM/HIGH skilled
- const team = []; // only HIGH skilled
- const allPlayers = [
- {
- name: 'personh1',
- skillLevel: 'HIGH'
- },
- {
- name: 'personh2',
- skillLevel: 'HIGH'
- },
- {
- name: 'personh3',
- skillLevel: 'HIGH'
- },
- {
- name: 'personm1',
- skillLevel: 'MEDIUM'
- },
- {
- name: 'personm2',
- skillLevel: 'MEDIUM'
- },
- {
- name: 'personl1',
- skillLevel: 'LOW'
- },
- {
- name: 'personl2',
- skillLevel: 'LOW'
- }
- ];
- const maxTeamSize = 2;
- const maxReservesSize = 2;
- allPlayers.forEach(p => {
- if (p.skillLevel === 'HIGH') {
- if (team.length < maxTeamSize) {
- team.push(p);
- } else {
- reserves.push(p);
- }
- } else if (p.skillLevel === 'MEDIUM') {
- if (reserves.length < maxReservesSize) {
- reserves.push(p);
- } else {
- excluded.push(p);
- }
- } else {
- excluded.push(p);
- }
- });
- // functions defined elsewhere...
- notifyOfInclusion(team.concat(reserves));
- notifyOfExclusion(excluded);
- team = R.slice(0, maxTeamSize, R.filter(p => p.skillLevel === 'HIGH', allPlayers));
- reserves = R.slice(0, maxReservesSize, R.filter(p => (p.skillLevel === 'HIGH' || p.skillLevel === 'MEDIUM') && !R.contains(p, team), allPlayers));
- excluded = R.filter(p => !R.contains(p, team) && !R.contains(p, reserves), allPlayers);
- notifyOfInclusion(team.concat(reserves));
- notifyOfExclusion(excluded);
Add Comment
Please, Sign In to add comment