Skip to content

Commit

Permalink
combine game high&standard (#53)
Browse files Browse the repository at this point in the history
* combine game high&standard
  • Loading branch information
adm2656 authored and homerchen19 committed Nov 20, 2017
1 parent 275ef28 commit a81d36f
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/command/game/boxScore.js
@@ -1,15 +1,17 @@
import { basicTable } from '../../utils/table';
import { bold, neonGreen } from '../../utils/log';
import { bold, neonGreen, nbaRed } from '../../utils/log';

const alignCenter = columns =>
columns.map(content => ({ content, hAlign: 'left', vAlign: 'center' }));

const checkOverStandard = (record, standard) =>
+record >= standard ? neonGreen(record) : record;
+record >= standard ? nbaRed(record) : record;

const checkGameHigh = (players, record, recordVal) => {
const checkGameHigh = (players, record, recordVal, standard) => {
const recordArr = players.map(player => Number.parseInt(player[record], 10));
return recordVal >= Math.max(...recordArr) ? neonGreen(recordVal) : recordVal;
return recordVal >= Math.max(...recordArr)
? neonGreen(recordVal)
: checkOverStandard(recordVal, standard);
};

const createTeamBoxScore = team => {
Expand Down Expand Up @@ -75,20 +77,20 @@ const createTeamBoxScore = team => {
alignCenter([
bold(`${first_name} ${last_name}`),
bold(position_short),
checkGameHigh(players, 'minutes', minutes),
checkGameHigh(players, 'minutes', minutes, 35),
`${field_goals_made}-${field_goals_attempted}`,
`${three_pointers_made}-${three_pointers_attempted}`,
`${free_throws_made}-${free_throws_attempted}`,
checkGameHigh(players, 'plus_minus', plus_minus),
checkGameHigh(players, 'rebounds_offensive', rebounds_offensive),
checkGameHigh(players, 'rebounds_defensive', rebounds_defensive),
checkOverStandard(totalRebounds, 10),
checkGameHigh(players, 'assists', assists),
checkGameHigh(players, 'steals', steals),
checkGameHigh(players, 'blocks', blocks),
checkGameHigh(players, 'turnovers', turnovers),
checkGameHigh(players, 'fouls', fouls),
checkGameHigh(players, 'points', points),
checkGameHigh(players, 'plus_minus', plus_minus, 15),
checkGameHigh(players, 'rebounds_offensive', rebounds_offensive, 10),
checkGameHigh(players, 'rebounds_defensive', rebounds_defensive, 10),
checkGameHigh(players, 'totalRebounds', totalRebounds, 10),
checkGameHigh(players, 'assists', assists, 10),
checkGameHigh(players, 'steals', steals, 5),
checkGameHigh(players, 'blocks', blocks, 5),
checkGameHigh(players, 'turnovers', turnovers, 5),
checkGameHigh(players, 'fouls', fouls, 6),
checkGameHigh(players, 'points', points, 20),
])
);
});
Expand Down

0 comments on commit a81d36f

Please sign in to comment.