qpjs
Quien Pasa? - JS. A very silly library to tell who wins on two-legged knockout series
Why doing this?
Short answer: just for fun.
Long answer: at SCV we love fútbol. We were having arguments on a Copa Libertadores knockout leg about who will pass to the next stage considering the slightly convoluted system they have. One of us mentioned it would be nice to have an app for it. So this library would be useful for that.
Another (and maybe slightly more important) reason was this was a good excuse to do a super simple example on how to publish an npm module with all the niceties for a good dev environment (ES6, tests, linter)
Installation
npm install qpjs
Usage
var qp = ; data = teams: 'Blues' 'Reds' games: home: 2 away: 1 home: 3 away: 2 ; options = fullResult: false awayGoalsRule: true result = ;console; // "Blues"
This will return who would win on a two legged knockout stage according to data, Where:
-
data
is a plain javascript object withteams
andgames
teams
is an array with two strings with the names of the two teams. The first team is the one that is the home team in the first game. If not given, it defaults toTeam 1
andTeam 2
games
is an array with the results of the two games. Each result is a plain javascript object with ahome
and anaway
property
-
options
is a plain javascript object with options. It can be ommited as all options have defaults. Currently the following options are supportedfullResult
: defaults totrue
. If true, the result is returned as an object with both the winner (can beundefined
in case of a tie) and the reason. Iffalse
only a simplestring
with the winner name is returned (orundefined
in case of a tie)awayGoalsRule
: defaults totrue
. If true, away goals are taking into account in case of a tie in aggregate goals
-
When
fullResult
is true,reason
can take the following values:AGGREGATE
: winner just have more goals in aggregateAWAY_GOALS
: there is a tie on aggregate goals, but winner has more away goalsFULL_TIE
: teams are tied on both aggregate goals and away goalsTIE
: teams are tied on aggregate goals and away goals rule is not applied on this case
Refer to the tests for more usage examples.