Pairing session - Martin Cigorraga

                Never    
# Code Challenge: Authorizer

You must implement a function to authorize transactions for a specific account, which should comply with a set of predefined rules.

Please read the following instructions and feel free to ask as many questions as you may need.

## Input

The function **parameters** are:

- The transaction to be authorized
- The state of the customer account


The **transaction** contains at which establishment it took place (`merchant`), the value (`amount`), and when it happened (`time`).

The **account state** includes the following information:

- If the account is active (`active`)
- The available limit of the account (`availableLimit`).
- The history of transaction of that account (`history`).

## Output

The function output should be the account's state with any violations of the business rules. If there are no violations on the authorization, the return should be an empty array `[]`.

## Business rules

A transaction authorization should be compliant with the following rules:

- Transactions should not be accepted for an inactive account: `account-not-active`
- The value of the **first** transaction should not exceed 90% of the available limit: `first-transaction-above-threshold`
- It should not have more than 3 transactions for any merchant in an interval of 2 minutes: `high-frequency-small-interval`
- It should not have more than 1 transaction similar (same value and merchant) in an interval of 2 minutes: `doubled-transaction`

If all the rules are met, the value of the transaction should be deducted from the account available limit, and the history of transactions should be updated.

## Example of use case

The following pseudocode demonstrates the use of the function.

### Use case of transaction authorized

```javascript
transaction = {
    amount: 10,
    merchant: "Burger King",
    time: Date.now()
}
account = {
    active: true,
    availableLimit: 100,
    history: []
}

result = authorize(transaction, account)

result.account == {
    active: true,
    availableLimit: 90,
    history: [{
        amount: 10,
        merchant: "Burger King",
        time: 1629298219336
    }]
}
result.violations == []
```

### Use case of transaction denied

```javascript
transaction = {
    amount: 100,
    merchant: "Paris 6",
    time: Date.now()
}
account = {
    active: false,
    availableLimit: 100,
    history: []
}

result = authorize(transaction, account)

result.account == {
    active: false,
    availableLimit: 100,
    history: []
}
result.violations == ["account-not-active", "first-transaction-above-threshold"]
```

## Advices

Some advices may help you with this challenge but keep in mind that these are just suggestions, and you don't need to follow them.

- Consider starting with the implementation of a single business rule, and then continue with the following violations;
- Consider implementing a solution that is extensible rather than just implementing all the business rules listed in this challenge;
- Consider implementing a solution as if you would be implementing a service business rules. Avoid considering other factors outside the main logic.
- Test your solution!

Raw Text