#80 Calculating Batting Average
In baseball, the batting average is a simple and most common way to measure a hitter's performace. Batting average is calculated by taking all the players hits and dividing it by their number of at_bats, and it is usually displayed as a 3 digit decimal (i.e. 0.300).
Given a yankees table with the following schema,
-player_id STRING
-player_name STRING
-primary_position STRING
-games INTEGER
-at_bats INTEGER
-hits INTEGER
return a table with player_name, games, and batting_average.
We want batting_average to be rounded to the nearest thousandth, since that is how baseball fans are used to seeing it. Format it as text and make sure it has 3 digits to the right of the decimal (pad with zeroes if neccesary).
Next, order our resulting table by batting_average, with the highest average in the first row.
Finally, since batting_average is a rate statistic, a small number of at_bats can change the average dramatically. To correct for this, exclude any player who doesn't have at least 100 at bats.
Expected Output Table
-player_name STRING
-games INTEGER
-batting_average STRING
'매일매일개발 > Codewars' 카테고리의 다른 글
codewars #82Evil Autocorrect Prank (6kyu) (0) | 2018.07.19 |
---|---|
codewars #81 Format words into a sentence (6kyu) (0) | 2018.07.18 |
codewars #79 Human readable duration format (4kyu) (0) | 2018.07.13 |
codewars #78 Convert PascalCase string into snake_case (5kyu) (0) | 2018.07.12 |
codewars #77 Tortoise racing (6kyu) (0) | 2018.07.11 |