-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathM.html
314 lines (303 loc) · 15.3 KB
/
M.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<html>
<head>
<title>The JavaScript Encyclopedia: M</title>
<link rel="stylesheet" href="encyclopedia.css" type="text/css">
</head>
<body><h1>M</h1>
<h2 id="map">map</h2>
<h3 id="map Array prototype function"><code>map</code> <code>Array</code> prototype function</h3>
<p>Blah.</p>
<pre>function expand_shorthand(hand) {
return hand.map(function (value) {
return {
rank: value.slice(0, -1),
suit: value.slice(-1)
};
});
});
var hand = expand_shorthand(['AH', 'KH', 'QH', 'JH', '10H']);
// hand is [
// {suit: 'H', rank: 'A'},
// {suit: 'H', rank: 'K'},
// {suit: 'H', rank: 'Q'},
// {suit: 'H', rank: 'J'},
// {suit: 'H', rank: '10'}
// ]
</pre>
<h2 id="match">match</h2>
<h3 id="match String prototype function"><code>match</code> <code>String</code> prototype function</h3>
<p>Blah.</p>
<h2 id="Math">Math</h2>
<h3 id="Math function"><code>Math</code> function</h3>
<p>The standard does not require implementations to compute the most accurate result from these functions. Implementors are allowed to tradeoff accuracy for speed or other considerations. Blah.</p>
<ul>
<li><a href="A.html#abs Math function"><code>abs</code> Math function</a> <dfn>absolute value</dfn></li>
<li><a href="A.html#acosMath function"><code>acos</code> Math function</a> <dfn>arc cosine</dfn></li>
<li><a href="A.html#asin Math function"><code>asin</code> Math function</a> <dfn>arc sine</dfn></li>
<li><a href="A.html#atan Math function"><code>atan</code> Math function</a> <dfn>arc tangent</dfn></li>
<li><a href="A.html#atan2 Math function"><code>atan2</code> Math function</a> <dfn>arc tangent y/x</dfn></li>
<li><a href="C.html#ceil Math function"><code>ceil</code> Math function</a> <dfn>ceiling</dfn></li>
<li><a href="C.html#os Math function"><code>cos</code> Math function</a> <dfn>cosine</dfn></li>
<li><a href="E.html#exp Math function"><code>exp</code> Math function</a> <dfn>exponential</dfn></li>
<li><a href="F.html#floor Math function"><code>floor</code> Math function</a></li>
<li><a href="L.html#log Math function"><code>log</code> Math function</a></li>
<li><a href="M.html#max Math function"><code>max</code> Math function</a></li>
<li><a href="M.html#min Math function"><code>min</code> Math function</a></li>
<li><a href="P.html#pow Math function"><code>pow</code> Math function</a> <dfn>raise to a power</dfn></li>
<li><a href="R.html#random Math function"><code>random</code> Math function</a></li>
<li><a href="R.html#round Math function"><code>round</code> Math function</a></li>
<li><a href="S.html#sin Math function"><code>sin</code> Math function</a> <dfn>sin</dfn></li>
<li><a href="S.html#sqrt Math function"><code>sqrt</code> Math function</a> <dfn>square root</dfn></li>
<li><a href="T.html#tan Math function"><code>tan</code> Math function</a> <dfn>tangent</dfn></li>
</ul>
<p>Most of the functions can take one parameter. These are the results of those functions for some particular arguments:</p>
<table border="1">
<tr>
<th rowspan="2">Math<br>
function</th>
<th colspan="5">Value of a single argument</th>
</tr>
<tr>
<th><code>NaN</code></th>
<th><code>-0</code></th>
<th><code>0</code></th>
<th><code>-Infinity</code></th>
<th><code>Infinity</code></th>
</tr>
<tr>
<td align="left"><code>abs</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>Infinity</code></td>
<td align="center"><code>Infinity</code></td>
</tr>
<tr>
<td align="left"><code>acos</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>Math.PI / 2</code></td>
<td align="center"><code>Math.PI / 2</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>NaN</code></td>
</tr>
<tr>
<td align="left"><code>asin</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>NaN</code></td>
</tr>
<tr>
<td align="left"><code>atan</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>-Math.PI / 2</code></td>
<td align="center"><code>Math.PI / 2</code></td>
</tr>
<tr>
<td align="left"><code>ceil</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>-Infinity</code></td>
<td align="center"><code>Infinity</code></td>
</tr>
<tr>
<td align="left"><code>cos</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>1</code></td>
<td align="center"><code>1</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>NaN</code></td>
</tr>
<tr>
<td align="left"><code>exp</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>1</code></td>
<td align="center"><code>1</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>Infinity</code></td>
</tr>
<tr>
<td align="left"><code>floor</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>-Infinity</code></td>
<td align="center"><code>Infinity</code></td>
</tr>
<tr>
<td align="left"><code>log</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-Infinity</code></td>
<td align="center"><code>-Infinity</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>Infinity</code></td>
</tr>
<tr>
<td align="left"><code>max</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>-Infinity</code></td>
<td align="center"><code>Infinity</code></td>
</tr>
<tr>
<td align="left"><code>min</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>-Infinity</code></td>
<td align="center"><code>Infinity</code></td>
</tr>
<tr>
<td align="left"><code>round</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>-Infinity</code></td>
<td align="center"><code>Infinity</code></td>
</tr>
<tr>
<td align="left"><code>sin</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>NaN</code></td>
</tr>
<tr>
<td align="left"><code>sqrt</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>Infinity</code></td>
</tr>
<tr>
<td align="left"><code>tan</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>-0</code></td>
<td align="center"><code>0</code></td>
<td align="center"><code>NaN</code></td>
<td align="center"><code>NaN</code></td>
</tr>
</table>
<p><code>Math.max(</code>...<code>)</code> and <code>Math.min(</code>...<code>)</code> can take many arguments. The table shows the case where there is one argument. </p>
<p><code>Math.atan2(y, x)</code> and <code>Math.pow(x, y)</code> each take two arguments. <code>Math.random()</code> takes no arguments.</p>
<h3 id="Math global object"><code>Math</code> global object</h3>
<p>Blah.</p>
<h3 id="Math number"><code>Math</code> number</h3>
<p>The <a href="#Math global object"><code>Math</code> global object</a> is the container for these numeric properties:</p>
<ul>
<li><a href="E.html#E Math number"><code>E</code> <code>Math</code> number</a> <dfn>e</dfn></li>
<li><a href="L.html#LN10 Math number"><code>LN10</code> <code>Math</code> number</a> <dfn>natural logarithm of 10</dfn></li>
<li><a href="L.html#LN2 Math number"><code>LN2</code> <code>Math</code> number</a> <dfn>natural logarithm of 2</dfn></li>
<li><a href="L.html#LOG10E Math number"><code>LOG10E</code> <code>Math</code> number</a> <dfn>base 10 logarithm of e</dfn></li>
<li><a href="L.html#LOG2E Math number"><code>LOG2E</code> <code>Math</code> number</a> <dfn>base 2 logarithm of e</dfn></li>
<li><a href="P.html#PI Math number"><code>PI</code> <code>Math</code> number</a> <dfn>pi</dfn></li>
<li><a href="S.html#SQRT1_2 Math number"><code>SQRT1_2</code> <code>Math</code> number</a> <dfn>square root of 0.5</dfn></li>
<li><a href="S.html#SQRT2 Math number"><code>SQRT2</code> <code>Math</code> number</a> <dfn>square root of 2</dfn></li>
</ul>
<h2 id="max">max</h2>
<h3 id="max Math function"><code>max</code> <code>Math</code> function</h3>
<p>The <code>Math.max(</code><var>...</var><code>)</code> function returns the largest number from its arguments. It can take a variable number of arguments. If there are no arguments, it returns <a href="I.html#Infinity"><code>-Infinity</code></a>. If there is one argument, it returns the numeric value of that argument. Otherwise, it compares each of the arguments and returns the greatest. If any of the arguments is <a href="N.html#NaN"><code>NaN</code></a> or converts to <a href="N.html#NaN"><code>NaN</code></a>, then the result is <a href="N.html#NaN"><code>NaN</code></a>. Unlike the <a href="special.html#less infix operator"><code>></code> infix operator</a>, <code>Math.max(</code><var>...</var><code>)</code> sees -0 as being less than 0 (see <a href="Z.html#zero">zero</a>).</p>
<p>It could be implemented like this:</p>
<pre>Math.max = function () {
var i, length = arguments.length, result = -Infinity, value;
for (i = 0; i < length; i += 1) {
value = +arguments[i];
if (isNaN(value)) {
return NaN;
}
if (value > result ||
(value === 0 && result === 0 && 1 / value > 0)) {
result = value;
}
}
return result;
};</pre>
<pre>Math.max(25, 52) // 52
Math.max(-1, 0.1, -0.1) // 0.1
Math.max('2', '10') // 10</pre>
<p>To find the greatest element in an <a href="A.html#array">array</a>, use the <a href="A.html#apply">apply</a> prototype function. </p>
<pre>Math.max.apply(null, [40, 8, Math.PI, 1000, 1]) // 1000</pre>
<h2 id="MAX_VALUE">MAX_VALUE</h2>
<h3 id="MAX_VALUE Number number"><code>MAX_VALUE</code> <code>Number</code> number</h3>
<p><code>Number.MAX_VALUE</code> contains the largest positive representable number. It is approximately equal to 1.7976931348623157e+308. A result which is larger than <code>MAX_VALUE</code> is represented as <a href="I.html#Infinity"><code>Infinity</code></a>. Surprisingly, <code>Number.MAX_VALUE + </code><var>x</var> where <var>x</var> is a non-negative number in most cases does not produce <a href="I.html#Infinity"><code>Infinity</code></a>. If <var>x</var> is less than approximately 9.979201547673598e+291 then the result of the addition is <code>MAX_VALUE</code> and not <a href="I.html#Infinity"><code>Infinity</code></a>. As a result, even given infinite time, this loop will never break<a href="I.html#Infinity"><code></code></a>:</p>
<pre>for (var x = Number.MAX_VALUE; x !== Infinity; x += 9.979201547673598e+291) {
x += 1;
}</pre>
<h2 id="member">member</h2>
<p>Also known as <a href="P.html#property">property</a>. See <a href="O.html#object">object</a>.</p>
<h2 id="memoization">memoization</h2>
<p>Blah.</p>
<pre>function memoizer(memo, formula) {
var recur = function (n) {
var result = memo[n];
if (typeof result !== 'number') {
result = formula(recur, n);
memo[n] = result;
}
return result;
};
return recur;
};
var factorial = memoizer([1, 1], function (recur, n) {
return n * recur(n - 1);
});
var fibonacci = memoizer([0, 1], function (recur, n) {
return recur(n - 1) + recur(n - 2);
});</pre>
<h2 id="method">method</h2>
<p>A method is <a href="P.html#property">property</a> whose value is a <a href="F.html#function">function</a>. The <a href="F.html#function">function</a> gets access to the <a href="O.html#object">object</a> with the <a href="T.html#this"><code>this</code> parameter</a>. See <a href="L.html#lvalue">invocation</a>.</p>
<p>All values except <code>null</code> and <code>undefined</code> can have methods.</p>
<h2>method chaining</h2>
<p>See <a href="C.html#cascading">cascading</a>.</p>
<h2 id="min">min</h2>
<h3 id="min Math function"><code>min</code> <code>Math</code> function</h3>
<p>The <code>Math.min(</code><var>...</var><code>)</code> function returns the smallest number from its arguments. It can take a variable number of arguments. If there are no arguments, it returns <a href="I.html#Infinity"><code>Infinity</code></a>. If there is one arguments, it returns the numeric value of that argument. Otherwise, it compares each of the arguments and returns the lowest. If any of the arguments is <a href="N.html#NaN"><code>NaN</code></a> or converts to <a href="N.html#NaN"><code>NaN</code></a>, then the result is <a href="N.html#NaN"><code>NaN</code></a>. Unlike the <a href="special.html#less infix operator"><code><</code> infix operator</a>, <code>Math.min(</code><var>...</var><code>)</code> sees -0 as being less than 0 (see <a href="Z.html#zero">zero</a>). It could be implemented like this:</p>
<pre>Math.min = function () {
var i, length = arguments.length, result = Infinity, value;
for (i = 0; i < length; i += 1) {
value = +arguments[i];
if (isNaN(value)) {
return NaN;
}
if (value < result ||
(value === 0 && result === 0 && 1 / value < 0)) {
result = value;
}
}
return result;
};</pre>
<pre>Math.min(25, 52) // 25
Math.min(-1, 0.1, -0.1) // -1
Math.min('2', '10') // 2</pre>
<p>To find the least element in an <a href="A.html#array">array</a>, use the <a href="A.html#append">append</a> prototype function. </p>
<pre>Math.min.apply(null, [40, 8, Math.PI, 1000, 1]) // 1</pre>
<h2 id="minus sign">minification</h2>
<p>Blah.</p>
<h2>minus sign</h2>
<p>See <a href="special.html#minus"><code>-</code></a> <dfn>minus sign</dfn>.</p>
<h2 id="MIN_VALUE">MIN_VALUE</h2>
<h3 id="MIN_VALUE Number number"><code>MIN_VALUE</code> <code>Number</code> number</h3>
<p><code>Number.MIN_VALUE</code> is the smallest positive number that can be represented. It is approximately equal to 5e-324. Dividing this value by 2 produces 0.</p>
<h2>modulo</h2>
<p>Blah.</p>
<p>See <a href="special.html#% infix operator"><code>%</code> infix operator</a> <dfn>remainder</dfn>.</p>
<h2 id="monad">monad</h2>
<p>Blah.</p>
<h2 id="monkey patching">monkey patching</h2>
<p>Blah.</p>
<h2>multiline</h2>
<h3 id="multiline Regexp"><code>multiline</code> <code>RegExp</code> instance number</h3>
<p>Blah.</p>
<h2 id="mutability">multiply</h2>
<p>See <a href="special.html#asterisk infix operator"><code>*</code> infix operator</a> <dfn>multiply</dfn>.</p>
<h2>mutability</h2>
<p>Blah.</p>
</body>
</html>