## algorithm

### description

Give you n non-negative integers a1, a2,..., an, each of which represents a point (i, ai) in the coordinates. Draw n vertical lines in the coordinates. The two end points of the vertical line i are (i, ai) and (i, 0). Find two of the lines so that the container that they form with the x-axis can hold the most water.

Explanation: You cannot tilt the container, and the value of n is at least 2.

The vertical line in the figure represents the input array [1,8,6,2,5,4,8,3,7]. In this case, the maximum value that the container can hold water (shown as the blue part) is 49.

Example:

```Input: [1,8,6,2,5,4,8,3,7]
Output: 49```

### analysis

The solution to this problem is similar `盛雨水`, using double pointers.

### Code

```/**
* @param {number[]} height
* @return {number}
*/
var maxArea = function (height) {
let i = 0, j = height.length-1;
let square, max = 0;
while (j-i >= 1) {
if (height[i]> height[j]) {
square = height[j] * (j-i);
j--;
} else {
square = height[i] * (j-i);
i++;
}
max = Math.max(square, max);
}
return max;
};```

### Talk about the Promises/A+ specification

Term introduction

`promise`: Have is a `then`method of an object or function, its actions are consistent with this specification `thenable`: a definition of the `then`object or function methods. This is mainly used to be compatible with some old Promise implementations. As long as a Promise implementation is thenable, that is, it has `then`methods, it can be compatible with Promises/A+. `value`: Refers `reslove`out value can be any valid value JS (including `undefined`, thenable promise and the like) `exception`: abnormal, in which a Promise `throw`thrown value `reason`: rejection reason is `reject`inside the transmission parameter indicating `reject`the reason of

status

`pending`: A promise is in this state before resolve or reject. `fulfilled`: A promise is in a `fulfilled`state after being resolved , this state cannot be changed, and must have an immutable value ( `value`). `rejected`: A promise is in a `rejected`state after being rejected , and this state cannot be changed, and it must have an immutable rejection reason ( `reason`).

then method

`promise.then(fulfilledFn, rejectedFn)`

catch method

`promise.catch(rejectedFn)`

Of course, the new ES specification `async`, `await`handles asynchronous is `Promise`+ `generator`implemented, the specific implementation set forth in the specification content of tomorrow.

``11. The container with the most water: https://leetcode-cn.com/problems/container-with-most-water/