This repository has been archived by the owner on May 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
executable file
·451 lines (354 loc) · 55.8 KB
/
index.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Maddy object operations library</title>
<link rel="stylesheet" href="docs/docs.css" media="screen">
</head>
<body>
<h1 id="maddy">Maddy</h1>
<p><strong>Maddy</strong> is a functional object operations library. It provides various <a href="http://en.wikipedia.org/wiki/Higher-order_function">higher-order functions</a> typical of a functional programming library, as well as specialized methods for determining deep equality and recursively serializing objects. All recursive methods fully support cyclic structures.</p>
<p>Maddy is compatible with web browsers, <a href="http://www.commonjs.org/">CommonJS</a> environments, JavaScript engines, and asynchronous script loaders. It also normalizes infamous bugs present in older environments.</p>
<p>The project is <a href="http://github.com/kitcambridge/maddy">hosted on GitHub</a>, along with the <a href="tests/tests.html">unit tests</a> and <a href="docs/index.html">annotated source code</a>. You can use the <a href="http://github.com/kitcambridge/maddy/issues">GitHub issue tracker</a> to submit bug reports and discuss feature requests, or send tweets to <a href="http://twitter.com/kitcambridge">@kitcambridge</a>.</p>
<h2 id="downloads">Downloads</h2>
<p>The current version is <strong>0.3.0</strong>.</p>
<table>
<tbody>
<tr>
<td><strong>Development Version</strong></td>
<td><a href="lib/maddy.js">Download</a> <em>(26 KB, commented and uncompressed)</em></td>
</tr>
<tr>
<td><strong>Production Version</strong></td>
<td><a href="lib/maddy.min.js">Download</a> <em>(2.3 KB, compressed using <a href="http://closure-compiler.appspot.com/home">Closure Compiler</a>)</em></td>
</tr>
</tbody>
</table>
<h2 id="table-of-contents">Table of Contents</h2>
<table>
<tbody>
<tr>
<td><strong>Utility Methods</strong></td>
<td><a href="#noConflict">noConflict</a>, <a href="#curry">curry</a></td>
</tr>
<tr>
<td><strong>Generic Methods</strong></td>
<td><a href="#isPropertyOf">isPropertyOf</a>, <a href="#getClassOf">getClassOf</a>, <a href="#isEqual">isEqual</a>, <a href="#stringify">stringify</a>, <a href="#isEmpty">isEmpty</a>, <a href="#keys">keys</a>, <a href="#extend">extend</a></td>
</tr>
<tr>
<td><strong>Functional Methods</strong></td>
<td><a href="#forEach">forEach</a>, <a href="#map">map</a>, <a href="#fold">fold</a>, <a href="#some">some</a>, <a href="#select">select</a>, <a href="#invoke">invoke</a>, <a href="#all">all</a>, <a href="#reject">reject</a>, <a href="#max">max</a>, <a href="#min">min</a>, <a href="#partition">partition</a>, <a href="#groupBy">groupBy</a></td>
</tr>
</tbody>
</table>
<h2 id="utility-methods">Utility Methods</h2>
<h3 id="noConflict">noConflict <code>Maddy.noConflict()</code></h3>
<p>Restores the original value of the global <code>Maddy</code> variable and returns a reference to the Maddy object. <em><code>noConflict</code> is not available in CommonJS environments, and <strong>cannot be invoked more than once</strong></em>.</p>
<div><div class="highlight"><pre><span class="kd">var</span> <span class="nx">Associative</span> <span class="o">=</span> <span class="nx">Maddy</span><span class="p">.</span><span class="nx">noConflict</span><span class="p">();</span>
<span class="k">typeof</span> <span class="nx">Maddy</span><span class="p">;</span>
<span class="c1">// => The type of the original value of the `Maddy` variable.</span>
<span class="c1">// `noConflict` can only be invoked once.</span>
<span class="k">typeof</span> <span class="nx">Associative</span><span class="p">.</span><span class="nx">noConflict</span><span class="p">;</span>
<span class="c1">// => "undefined"</span>
<span class="k">typeof</span> <span class="nx">Associative</span><span class="p">.</span><span class="nx">map</span><span class="p">;</span>
<span class="c1">// => "function"</span>
</pre></div>
</div>
<h3 id="curry">curry <code>Maddy.curry(function, [*arguments])</code></h3>
<p>Partially applies a <strong>function</strong>, returning a function that, when invoked, calls the original <strong>function</strong> with the <strong>arguments</strong> prepended to any additional arguments.</p>
<p><code>curry</code> can be invoked on itself (i.e., <code>Maddy.curry(Maddy.curry, ...)</code>) to produce a function that, when called, will return a curried function for further partial application. <code>curry</code> can also be used with other higher-order functions, providing a convenient way to invoke a single callback function on multiple objects.</p>
<div><div class="highlight"><pre><span class="kd">function</span> <span class="nx">convert</span><span class="p">(</span><span class="nx">ratio</span><span class="p">,</span> <span class="nx">symbol</span><span class="p">,</span> <span class="nx">input</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="p">(</span><span class="nx">input</span> <span class="o">*</span> <span class="nx">ratio</span><span class="p">).</span><span class="nx">toFixed</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="s2">" "</span> <span class="o">+</span> <span class="nx">symbol</span><span class="p">;</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">pounds</span> <span class="o">=</span> <span class="nx">Maddy</span><span class="p">.</span><span class="nx">curry</span><span class="p">(</span><span class="nx">convert</span><span class="p">,</span> <span class="mf">2.2</span><span class="p">,</span> <span class="s2">"lbs."</span><span class="p">);</span>
<span class="nx">pounds</span><span class="p">(</span><span class="mi">4</span><span class="p">);</span>
<span class="c1">// => "8.8 lbs."</span>
<span class="kd">var</span> <span class="nx">pints</span> <span class="o">=</span> <span class="nx">Maddy</span><span class="p">.</span><span class="nx">curry</span><span class="p">(</span><span class="nx">convert</span><span class="p">,</span> <span class="mf">1.98</span><span class="p">);</span>
<span class="nx">pints</span><span class="p">(</span><span class="s2">"U.S. pints"</span><span class="p">,</span> <span class="mf">2.4</span><span class="p">);</span>
<span class="c1">// => "4.8 U.S. pints"</span>
<span class="kd">var</span> <span class="nx">meta</span> <span class="o">=</span> <span class="nx">Maddy</span><span class="p">.</span><span class="nx">curry</span><span class="p">(</span><span class="nx">Maddy</span><span class="p">.</span><span class="nx">curry</span><span class="p">,</span> <span class="nx">convert</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">kilometers</span> <span class="o">=</span> <span class="nx">meta</span><span class="p">(</span><span class="mf">1.62</span><span class="p">,</span> <span class="s2">"km"</span><span class="p">);</span>
<span class="nx">kilometers</span><span class="p">(</span><span class="mi">34</span><span class="p">);</span>
<span class="c1">// => "55.1 km"</span>
<span class="kd">var</span> <span class="nx">callback</span> <span class="o">=</span> <span class="nx">Maddy</span><span class="p">.</span><span class="nx">curry</span><span class="p">(</span><span class="nx">Maddy</span><span class="p">.</span><span class="nx">forEach</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">key</span> <span class="o">+</span> <span class="s2">": "</span> <span class="o">+</span> <span class="nx">value</span><span class="p">);</span>
<span class="p">});</span>
<span class="nx">callback</span><span class="p">({</span><span class="s2">"jdalton"</span><span class="o">:</span> <span class="s2">"John-David"</span><span class="p">,</span> <span class="s2">"mathias"</span><span class="o">:</span> <span class="s2">"Mathias"</span><span class="p">});</span>
<span class="c1">// => Prints `"jdalton: John-David" and "mathias: Mathias"`</span>
<span class="nx">callback</span><span class="p">({</span><span class="s2">"kitcam"</span><span class="o">:</span> <span class="s2">"Kit"</span><span class="p">,</span> <span class="s2">"maddy"</span><span class="o">:</span> <span class="s2">"Maddy"</span><span class="p">});</span>
<span class="c1">// => Prints `"kitcam: Kit" and "maddy: Maddy"`</span>
</pre></div>
</div>
<h2 id="generic-methods">Generic Methods</h2>
<h3 id="isPropertyOf">isPropertyOf <code>Maddy.isPropertyOf(object, property)</code></h3>
<p>Determines if <strong>property</strong> is a direct property of the specified <strong>object</strong>.</p>
<div><div class="highlight"><pre><span class="kd">function</span> <span class="nx">Person</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">age</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="nx">name</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">age</span> <span class="o">=</span> <span class="nx">age</span><span class="p">;</span>
<span class="p">}</span>
<span class="nx">Person</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">say</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">message</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s2">": "</span> <span class="o">+</span> <span class="nx">message</span><span class="p">;</span>
<span class="p">};</span>
<span class="kd">var</span> <span class="nx">kit</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Person</span><span class="p">(</span><span class="s2">"Kit"</span><span class="p">,</span> <span class="mi">18</span><span class="p">);</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isPropertyOf</span><span class="p">(</span><span class="nx">kit</span><span class="p">,</span> <span class="s2">"name"</span><span class="p">);</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isPropertyOf</span><span class="p">(</span><span class="nx">kit</span><span class="p">,</span> <span class="s2">"age"</span><span class="p">);</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isPropertyOf</span><span class="p">(</span><span class="nx">kit</span><span class="p">,</span> <span class="s2">"say"</span><span class="p">);</span> <span class="c1">// => false</span>
</pre></div>
</div>
<h3 id="getClassOf">getClassOf <code>Maddy.getClassOf(object)</code></h3>
<p>Returns the internal <code>[[Class]]</code> name of the provided <strong>object</strong>. To account for cross-environment inconsistencies, only the following <code>[[Class]]</code> names are supported: <code>Function</code>, <code>Array</code>, <code>Date</code>, <code>RegExp</code>, <code>String</code>, <code>Boolean</code>, and <code>Number</code>.</p>
<p>Note that <code>Null</code> and <code>Undefined</code> are not <code>[[Class]]</code> names, but are implemented for parity with <code>Object::toString</code>.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">(</span><span class="kc">null</span><span class="p">);</span> <span class="c1">// => "Null"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">();</span> <span class="c1">// => "Undefined"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">(</span><span class="s2">"Maddy"</span><span class="p">);</span> <span class="c1">// => "String"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">(</span><span class="k">new</span> <span class="nb">String</span><span class="p">(</span><span class="s2">"Maddy"</span><span class="p">));</span> <span class="c1">// => "String"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span> <span class="c1">// => "Number"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">(</span><span class="k">new</span> <span class="nb">Boolean</span><span class="p">(</span><span class="kc">true</span><span class="p">));</span> <span class="c1">// => "Boolean"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">({});</span> <span class="c1">// => "Object"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">([]);</span> <span class="c1">// => "Array"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{});</span> <span class="c1">// => "Function"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">(</span><span class="sr">/(?:)/</span><span class="p">);</span> <span class="c1">// => "RegExp"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">getClassOf</span><span class="p">(</span><span class="k">new</span> <span class="nb">Date</span><span class="p">);</span> <span class="c1">// => "Date"</span>
</pre></div>
</div>
<h3 id="isEqual">isEqual <code>Maddy.isEqual([left, right])</code></h3>
<p>Recursively compares two objects (<code>left</code> and <code>right</code>) using the following algorithm:</p>
<ul>
<li>Identical values (<code>left === right</code>) are automatically equivalent.</li>
<li><code>0</code> is <a href="http://wiki.ecmascript.org/doku.php?id=harmony:egal">not equal</a> to <code>-0</code>.</li>
<li>Objects with different <code>[[Class]]</code> names are not equivalent.</li>
<li><code>null</code>, <code>undefined</code>, and functions are compared by identity.</li>
<li>Strings, numbers, and booleans are compared by value. Primitives and their corresponding object wrappers are equivalent; hence, <code>"5"</code> is equivalent to <code>new String("5")</code>.</li>
<li><code>NaN</code> is equivalent to <code>NaN</code>.</li>
<li>Dates are compared by their millisecond representations. Invalid dates (e.g, <code>new Date("Maddy")</code>) are not equivalent.</li>
<li>RegExps are compared by their source patterns and flags.</li>
<li>Arrays must contain equivalent contents. Non-numeric properties are ignored; sparse arrays (e.g., <code>Array(10)</code>) are supported.</li>
<li>Objects must contain equivalent <strong>direct members</strong>. Members in the prototype chain are ignored.</li>
</ul>
<p><em>Note: JScript 5, implemented in Internet Explorer 6-8, <strong>treats <code>undefined</code> elements in arrays as elisions</strong>. Thus, in Internet Explorer, sparse arrays (<code>Array(3)</code>) are equivalent to dense arrays containing <code>undefined</code> values (<code>[undefined, undefined, undefined]</code>).</em></p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">0</span><span class="p">);</span> <span class="c1">// => false</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="s2">""</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="c1">// => false</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="kc">false</span><span class="p">,</span> <span class="s2">""</span><span class="p">);</span> <span class="c1">// => false</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="kc">undefined</span><span class="p">);</span> <span class="c1">// => false</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="s2">"Kit"</span><span class="p">,</span> <span class="k">new</span> <span class="nb">String</span><span class="p">(</span><span class="s2">"Kit"</span><span class="p">));</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="k">new</span> <span class="nb">String</span><span class="p">(</span><span class="s2">"Kit"</span><span class="p">),</span> <span class="k">new</span> <span class="nb">String</span><span class="p">(</span><span class="s2">"Kit"</span><span class="p">));</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="k">new</span> <span class="nb">Number</span><span class="p">(</span><span class="mi">3</span><span class="p">),</span> <span class="k">new</span> <span class="nb">Number</span><span class="p">(</span><span class="mi">3</span><span class="p">));</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="kc">NaN</span><span class="p">,</span> <span class="kc">NaN</span><span class="p">);</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="mi">2009</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">9</span><span class="p">),</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="mi">2009</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">9</span><span class="p">));</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="s2">"Kit"</span><span class="p">),</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="s2">"Kit"</span><span class="p">));</span> <span class="c1">// => false;</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="sr">/(?:)/gim</span><span class="p">,</span> <span class="sr">/(?:)/gim</span><span class="p">);</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="sr">/(?:)/gi</span><span class="p">,</span> <span class="sr">/(?:)/gm</span><span class="p">);</span> <span class="c1">// => false</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="sr">/Kit/gm</span><span class="p">,</span> <span class="sr">/Maddy/gm</span><span class="p">);</span> <span class="c1">// => false</span>
<span class="kd">var</span> <span class="nx">elements</span> <span class="o">=</span> <span class="p">[],</span> <span class="nx">equivalent</span> <span class="o">=</span> <span class="p">[];</span>
<span class="nx">elements</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">elements</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="k">new</span> <span class="nb">String</span><span class="p">(</span><span class="s2">"Kit"</span><span class="p">),</span> <span class="k">new</span> <span class="nb">Number</span><span class="p">(</span><span class="mi">3</span><span class="p">),</span> <span class="nx">elements</span><span class="p">);</span>
<span class="nx">equivalent</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">equivalent</span><span class="p">,</span> <span class="k">new</span> <span class="nb">Number</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="k">new</span> <span class="nb">String</span><span class="p">(</span><span class="s2">"Kit"</span><span class="p">),</span> <span class="mi">3</span><span class="p">,</span> <span class="nx">equivalent</span><span class="p">);</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="nx">elements</span><span class="p">,</span> <span class="nx">equivalent</span><span class="p">);</span> <span class="c1">// => true</span>
<span class="nx">elements</span> <span class="o">=</span> <span class="p">{};</span>
<span class="nx">equivalent</span> <span class="o">=</span> <span class="p">{};</span>
<span class="nx">elements</span><span class="p">.</span><span class="nx">elements</span> <span class="o">=</span> <span class="nx">elements</span><span class="p">;</span>
<span class="nx">equivalent</span><span class="p">.</span><span class="nx">elements</span> <span class="o">=</span> <span class="nx">equivalent</span><span class="p">;</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="nx">elements</span><span class="p">,</span> <span class="nx">equivalent</span><span class="p">);</span> <span class="c1">// => true</span>
</pre></div>
</div>
<h3 id="stringify">stringify <code>Maddy.stringify(object)</code></h3>
<p>Returns a debug-oriented representation of an object, similar to <code>JSON.stringify</code>. Objects are serialized according to a superset of the <a href="https://developer.mozilla.org/en/JSON">JSON encoding algorithm</a>:</p>
<ul>
<li>Booleans, finite numbers, and <code>null</code> are represented as such.</li>
<li>Cyclic structures, <code>Infinity</code>, <code>NaN</code>, invalid dates, and all other non-JSON values are serialized as <code>null</code>.</li>
<li>Strings are wrapped in double quotes. All JSON control characters are escaped.</li>
<li>Dates are converted to simplified ISO 8601 strings: <code>YYYY-MM-DDTHH:mm:ss.sssZ</code>.</li>
<li>RegExps are converted to their corresponding object representations.</li>
</ul>
<p><em>Note that custom <code>toJSON</code> methods are <strong>ignored</strong></em>.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">stringify</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">"Kit"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"name"</span><span class="o">:</span> <span class="s2">"Maddy"</span><span class="p">},</span> <span class="kc">NaN</span><span class="p">,</span> <span class="kc">Infinity</span><span class="p">]);</span>
<span class="c1">// => "[1, 2, 3, \"Kit\", {\"name\": \"Maddy\"}, null, null]"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="s2">"Hello\tthis\bis\\nice"</span><span class="p">);</span>
<span class="c1">// => "\"Hello\tthis\bis\\nice\""</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="sr">/(?:)/</span><span class="p">);</span>
<span class="c1">// => "{\"source\": \"(?:)\", \"global\": false, \"ignoreCase\": false, \"multiline\": false}"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">stringify</span><span class="p">({</span><span class="s2">"kitcam"</span><span class="o">:</span> <span class="p">[</span><span class="k">new</span> <span class="nb">String</span><span class="p">(</span><span class="s2">"Kit Cambridge"</span><span class="p">),</span> <span class="k">new</span> <span class="nb">Number</span><span class="p">(</span><span class="mi">18</span><span class="p">)]});</span>
<span class="c1">// => "{\"kitcam\": [\"Kit Cambridge\", 18]}"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nb">Date</span><span class="p">.</span><span class="nx">UTC</span><span class="p">(</span><span class="mi">1994</span><span class="p">,</span> <span class="mi">06</span><span class="p">,</span> <span class="mi">03</span><span class="p">)));</span>
<span class="c1">// => "\"1994-07-03T00:00:00.000Z\""</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">stringify</span><span class="p">();</span>
<span class="c1">// => "null"</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">stringify</span><span class="p">({</span><span class="s2">"value"</span><span class="o">:</span> <span class="k">new</span> <span class="nb">Boolean</span><span class="p">(</span><span class="kc">true</span><span class="p">),</span> <span class="s2">"toJSON"</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">value</span><span class="p">.</span><span class="nx">valueOf</span><span class="p">();</span>
<span class="p">}});</span>
<span class="c1">// => "{\"value\": true, \"toJSON\": null}"</span>
<span class="kd">var</span> <span class="nx">structure</span> <span class="o">=</span> <span class="p">[];</span>
<span class="nx">structure</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">structure</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">structure</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="nx">structure</span><span class="p">);</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">structure</span><span class="p">);</span>
<span class="c1">// => "[null, 2, null 4, null]"</span>
</pre></div>
</div>
<h3 id="isEmpty">isEmpty <code>Maddy.isEmpty(object)</code></h3>
<p>Checks if the provided <strong>object</strong> is empty using the following algorithm:</p>
<ul>
<li><code>null</code>, <code>undefined</code> <code>NaN</code>, <code>Infinity</code>, and dates with invalid millisecond values are empty.</li>
<li>Booleans, functions, and RegExps are never empty.</li>
<li>Strings and arrays are empty if they have a <code>length</code> of zero.</li>
<li>All other objects are empty if they contain no direct properties.</li>
</ul>
<p><em><code>isEmpty</code> <strong>does not distinguish</strong> between primitives and their corresponding object wrappers.</em></p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">(</span><span class="kc">null</span><span class="p">);</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">();</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">(</span><span class="kc">Infinity</span><span class="p">);</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">(</span><span class="kc">NaN</span><span class="p">);</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">(</span><span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="s2">"Invalid Date"</span><span class="p">));</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">({});</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]);</span> <span class="c1">// => false</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">(</span><span class="s2">""</span><span class="p">);</span> <span class="c1">// => true</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">(</span><span class="sr">/(?:)/</span><span class="p">);</span> <span class="c1">// => false</span>
</pre></div>
</div>
<h3 id="keys">keys <code>Maddy.keys(object)</code></h3>
<p>Returns a lexicographically-sorted array of an <strong>object</strong>’s property names.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">keys</span><span class="p">({</span><span class="s2">"first"</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">"second"</span><span class="o">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">"third"</span><span class="o">:</span> <span class="mi">3</span><span class="p">});</span>
<span class="c1">// => ["first", "second", "third"]</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">keys</span><span class="p">({</span><span class="s2">"name"</span><span class="o">:</span> <span class="s2">"Kit"</span><span class="p">,</span> <span class="s2">"age"</span><span class="o">:</span> <span class="mi">18</span><span class="p">,</span> <span class="nx">developer</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">hobbies</span><span class="o">:</span> <span class="p">[</span><span class="s2">"running"</span><span class="p">,</span> <span class="s2">"programming"</span><span class="p">]});</span>
<span class="c1">// => ["age", "developer", "hobbies", "name"]</span>
</pre></div>
</div>
<h3 id="extend">extend <code>Maddy.extend(destination, *sources)</code></h3>
<p>Extends a <strong>destination</strong> object with the properties of one or more <strong>sources</strong>.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span><span class="s2">"name"</span><span class="o">:</span> <span class="s2">"Kit"</span><span class="p">},</span> <span class="p">{</span><span class="s2">"age"</span><span class="o">:</span> <span class="mi">18</span><span class="p">},</span> <span class="p">{</span><span class="s2">"hobbies"</span><span class="o">:</span> <span class="p">[</span><span class="s2">"running"</span><span class="p">,</span> <span class="s2">"programming"</span><span class="p">]});</span>
<span class="c1">// => {"name": "Kit", "age": 18, "hobbies": ["running", "programming"]}</span>
</pre></div>
</div>
<h2 id="functional-methods">Functional Methods</h2>
<p><strong>Note</strong>: These methods <strong>should not be used with arrays</strong> or index-based collections, as they are exceedingly inefficient for this purpose. Consider <a href="http://documentcloud.github.com/underscore/">Underscore</a> or <a href="http://osteele.com/sources/javascript/functional/">Functional</a> instead.</p>
<h3 id="forEach">forEach <code>Maddy.forEach(callback, [context], object)</code></h3>
<p>Iterates over an <strong>object</strong>, invoking a <strong>callback</strong> function for each iteration. The iteration algorithm is normalized to account for cross-environment inconsistencies, including the <a href="https://developer.mozilla.org/en/ECMAScript_DontEnum_attribute">JScript <code>[[DontEnum]]</code> bug</a>, the Safari 2 <a href="http://web.archive.org/web/20090428222941/http://tobielangel.com/2007/1/29/for-in-loop-broken-in-safari/">property shadowing bug</a>, and inconsistent enumeration of the <code>prototype</code> and <code>constructor</code> properties.</p>
<p>The <strong>callback</strong> is bound to the optional <strong>context</strong> object, if one is specified, and accepts three arguments: <code>(key, value, object)</code>.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">pseudonym</span><span class="p">,</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">object</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">pseudonym</span> <span class="o">+</span> <span class="s2">": "</span> <span class="o">+</span> <span class="nx">name</span><span class="p">);</span>
<span class="p">},</span> <span class="p">{</span><span class="s2">"jdalton"</span><span class="o">:</span> <span class="s2">"John-David Dalton"</span><span class="p">,</span> <span class="s2">"kitcam"</span><span class="o">:</span> <span class="s2">"Kit Cambridge"</span><span class="p">});</span>
<span class="c1">// => Prints `"jdalton: John-David Dalton"` and `"kitcam: Kit Cambridge"`.</span>
</pre></div>
</div>
<h3 id="map">map, collect <code>Maddy.map(callback, [context], object)</code></h3>
<p>Returns an object containing the results of invoking a <strong>callback</strong> function on each <strong>object</strong> member.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">pseudonym</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="p">[</span><span class="nx">data</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">data</span><span class="p">.</span><span class="nx">age</span><span class="p">];</span>
<span class="p">},</span> <span class="p">{</span>
<span class="s2">"jdalton"</span><span class="o">:</span> <span class="p">{</span><span class="s2">"name"</span><span class="o">:</span> <span class="s2">"John-David"</span><span class="p">,</span> <span class="s2">"age"</span><span class="o">:</span> <span class="mi">29</span><span class="p">},</span>
<span class="s2">"kitcam"</span><span class="o">:</span> <span class="p">{</span><span class="s2">"name"</span><span class="o">:</span> <span class="s2">"Kit Cambridge"</span><span class="p">,</span> <span class="s2">"age"</span><span class="o">:</span> <span class="mi">18</span><span class="p">}</span>
<span class="p">});</span>
<span class="c1">// => {"jdalton": ["John-David", 29], "kitcam": ["Kit Cambridge", 18]}</span>
</pre></div>
</div>
<h3 id="fold">fold, inject, reduce <code>Maddy.fold(callback, [context], memo, object)</code></h3>
<p>Reduces an <strong>object</strong> to a single value by successively invoking the <strong>callback</strong> function on each member. <strong>memo</strong> specifies the initial state of the reduction; each <em>n</em>th invocation of <strong>callback</strong> should return the value of <strong>memo</strong> to be used in the <em>n+1</em>th invocation.</p>
<p>The <strong>callback</strong> function accepts four arguments: <code>(memo, key, value, object)</code>.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">fold</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">memo</span><span class="p">,</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">occupation</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">memo</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">occupation</span><span class="p">),</span> <span class="nx">memo</span><span class="p">;</span>
<span class="p">},</span> <span class="p">[],</span> <span class="p">{</span><span class="s2">"kitcam"</span><span class="o">:</span> <span class="s2">"programmer"</span><span class="p">,</span> <span class="s2">"maddy"</span><span class="o">:</span> <span class="s2">"runner"</span><span class="p">}).</span><span class="nx">sort</span><span class="p">();</span>
<span class="c1">// => ["kitcam", "maddy", "programmer", "runner"]</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">reduce</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">memo</span><span class="p">,</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">year</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">memo</span><span class="p">[</span><span class="nx">year</span><span class="p">]</span> <span class="o">=</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">memo</span><span class="p">;</span>
<span class="p">},</span> <span class="p">{},</span> <span class="p">{</span><span class="s2">"Perl"</span><span class="o">:</span> <span class="mi">1987</span><span class="p">,</span> <span class="s2">"Haskell"</span><span class="o">:</span> <span class="mi">1990</span><span class="p">,</span> <span class="s2">"JavaScript"</span><span class="o">:</span> <span class="mi">1996</span><span class="p">});</span>
<span class="c1">// => {1987: "Perl", 1990: "Haskell", 1996: "JavaScript"}</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">inject</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">memo</span><span class="p">,</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">age</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">memo</span> <span class="o">+</span> <span class="nx">age</span><span class="p">;</span>
<span class="p">},</span> <span class="mi">0</span><span class="p">,</span> <span class="p">{</span><span class="s2">"jdalton"</span><span class="o">:</span> <span class="mi">29</span><span class="p">,</span> <span class="s2">"kitcam"</span><span class="o">:</span> <span class="mi">18</span><span class="p">,</span> <span class="s2">"maddy"</span><span class="o">:</span> <span class="mi">17</span><span class="p">});</span>
<span class="c1">// => 64</span>
</pre></div>
</div>
<h3 id="some">some, any <code>Maddy.some(callback, [context], object)</code></h3>
<p>Determines if the <strong>callback</strong> returns <code>true</code> for at least one <strong>object</strong> member.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">some</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">year</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">name</span> <span class="o">></span> <span class="s2">"Lua"</span> <span class="o">&&</span> <span class="nx">year</span> <span class="o">></span> <span class="mi">1990</span><span class="p">;</span>
<span class="p">},</span> <span class="p">{</span><span class="s2">"Haskell"</span><span class="o">:</span> <span class="mi">1990</span><span class="p">,</span> <span class="s2">"JavaScript"</span><span class="o">:</span> <span class="mi">1996</span><span class="p">,</span> <span class="s2">"Python"</span><span class="o">:</span> <span class="mi">1991</span><span class="p">});</span>
<span class="c1">// => true</span>
</pre></div>
</div>
<h3 id="select">select, findAll, filter <code>Maddy.select(callback, [context], object)</code></h3>
<p>Returns an object containing all <strong>object</strong> members for which the <strong>callback</strong> returns <code>true</code>. <a href="#reject"><code>reject</code></a> is the opposite of this method.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">select</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">year</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">year</span> <span class="o">></span> <span class="mi">2007</span><span class="p">;</span>
<span class="p">},</span> <span class="p">{</span><span class="s2">"Functional"</span><span class="o">:</span> <span class="mi">2007</span><span class="p">,</span> <span class="s2">"Underscore"</span><span class="o">:</span> <span class="mi">2009</span><span class="p">,</span> <span class="s2">"Maddy"</span><span class="o">:</span> <span class="mi">2011</span><span class="p">});</span>
<span class="c1">// => {"Underscore": 2009, "Maddy": 2011}</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">findAll</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">year</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">name</span> <span class="o">></span> <span class="s2">"Sencha"</span> <span class="o">&&</span> <span class="nx">year</span> <span class="o">></span> <span class="mi">2007</span><span class="p">;</span>
<span class="p">},</span> <span class="p">{</span><span class="s2">"Prototype"</span><span class="o">:</span> <span class="mi">2005</span><span class="p">,</span> <span class="s2">"MooTools"</span><span class="o">:</span> <span class="mi">2006</span><span class="p">,</span> <span class="s2">"Underscore"</span><span class="o">:</span> <span class="mi">2009</span><span class="p">});</span>
<span class="c1">// => {"Underscore": 2009}</span>
</pre></div>
</div>
<h3 id="invoke">invoke, send <code>Maddy.invoke(object, method, [*arguments])</code></h3>
<p>Invokes a <strong>method</strong> with optional <strong>arguments</strong> on every <strong>object</strong> member value. <code>invoke</code> does not directly mutate the original object, but the object may be mutated by the <strong>method</strong>.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">invoke</span><span class="p">({</span><span class="mi">1990</span><span class="o">:</span> <span class="s2">"**Haskell**"</span><span class="p">,</span> <span class="mi">1993</span><span class="o">:</span> <span class="s2">"_*Ruby*_"</span><span class="p">},</span> <span class="s2">"slice"</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">);</span>
<span class="c1">// => {1990: "Haskell", 1993: "Ruby"}</span>
<span class="c1">// Note that the original object may be indirectly mutated by the invoked method.</span>
<span class="kd">var</span> <span class="nx">developers</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"mathias"</span><span class="o">:</span> <span class="p">[</span><span class="s2">"Mathias Bynens"</span><span class="p">,</span> <span class="mi">23</span><span class="p">],</span> <span class="s2">"kitcam"</span><span class="o">:</span> <span class="p">[</span><span class="s2">"Kit Cambridge"</span><span class="p">,</span> <span class="mi">18</span><span class="p">]};</span>
<span class="nx">Maddy</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="nx">developers</span><span class="p">,</span> <span class="s2">"shift"</span><span class="p">);</span>
<span class="c1">// => {"mathias": "Mathias Bynens", "kitcam": "Kit Cambridge"}</span>
<span class="nx">developers</span><span class="p">;</span>
<span class="c1">// => {"mathias": [23], "kitcam": [18]}</span>
</pre></div>
</div>
<h3 id="all">all, every <code>Maddy.all(callback, [context], object)</code></h3>
<p>Determines whether the <strong>callback</strong> returns <code>true</code> for all <strong>object</strong> members.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">all</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">year</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">name</span> <span class="o"><</span> <span class="s2">"Visual Basic"</span><span class="p">;</span>
<span class="p">},</span> <span class="p">{</span><span class="s2">"Haskell"</span><span class="o">:</span> <span class="mi">1990</span><span class="p">,</span> <span class="s2">"JavaScript"</span><span class="o">:</span> <span class="mi">1996</span><span class="p">,</span> <span class="s2">"Python"</span><span class="o">:</span> <span class="mi">1991</span><span class="p">});</span>
<span class="c1">// => true</span>
</pre></div>
</div>
<h3 id="reject">reject <code>Maddy.reject(callback, [context], object)</code></h3>
<p>Returns an object containing all <strong>object</strong> members for which the <strong>callback</strong> returns <code>false</code>. <a href="#select"><code>select</code></a> is the opposite of this method.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">reject</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">year</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">year</span> <span class="o">></span> <span class="mi">2010</span><span class="p">;</span>
<span class="p">},</span> <span class="p">{</span><span class="s2">"Backbone"</span><span class="o">:</span> <span class="mi">2010</span><span class="p">,</span> <span class="s2">"Underscore"</span><span class="o">:</span> <span class="mi">2009</span><span class="p">,</span> <span class="s2">"Maddy"</span><span class="o">:</span> <span class="mi">2011</span><span class="p">});</span>
<span class="c1">// => {"Backbone": 2010, "Underscore": 2009}</span>
</pre></div>
</div>
<h3 id="max">max <code>Maddy.max(callback, [context], object)</code></h3>
<p>Returns the key of the maximum <strong>object</strong> member-based computation. Members are compared by invoking the <strong>callback</strong> on each member and comparing successive return values.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">max</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">pseudonym</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">data</span><span class="p">.</span><span class="nx">age</span><span class="p">;</span>
<span class="p">},</span> <span class="p">{</span><span class="s2">"jdalton"</span><span class="o">:</span> <span class="p">{</span><span class="s2">"name"</span><span class="o">:</span> <span class="s2">"John-David"</span><span class="p">,</span> <span class="s2">"age"</span><span class="o">:</span> <span class="mi">29</span><span class="p">},</span> <span class="s2">"mathias"</span><span class="o">:</span> <span class="p">{</span><span class="s2">"name"</span><span class="o">:</span> <span class="s2">"Mathias"</span><span class="p">,</span> <span class="s2">"age"</span><span class="o">:</span> <span class="mi">23</span><span class="p">}});</span>
<span class="c1">// => "jdalton"</span>
</pre></div>
</div>
<h3 id="min">min <code>Maddy.min(callback, [context], object)</code></h3>
<p>Returns the key of the minimum <strong>object</strong> member-based computation.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">min</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">pseudonym</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">data</span><span class="p">.</span><span class="nx">age</span><span class="p">;</span>
<span class="p">},</span> <span class="p">{</span><span class="s2">"mathias"</span><span class="o">:</span> <span class="p">{</span><span class="s2">"name"</span><span class="o">:</span> <span class="s2">"Mathias"</span><span class="p">,</span> <span class="s2">"age"</span><span class="o">:</span> <span class="mi">23</span><span class="p">},</span> <span class="s2">"kitcam"</span><span class="o">:</span> <span class="p">{</span><span class="s2">"name"</span><span class="o">:</span> <span class="s2">"Kit"</span><span class="p">,</span> <span class="s2">"age"</span><span class="o">:</span> <span class="mi">18</span><span class="p">}});</span>
<span class="c1">// => "kitcam"</span>
</pre></div>
</div>
<h3 id="partition">partition <code>Maddy.partition(callback, [context], object)</code></h3>
<p>Separates an <strong>object</strong>’s members into two groups: those for which the <strong>callback</strong> returns <code>true</code>, and those for which it returns <code>false</code>. <code>partition</code> is preferred to invoking both <a href="#select"><code>select</code></a> and <a href="#reject"><code>reject</code></a> on the same <strong>object</strong>.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">partition</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">pseudonym</span><span class="p">,</span> <span class="nx">name</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">name</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">5</span><span class="p">;</span>
<span class="p">},</span> <span class="p">{</span><span class="s2">"jdalton"</span><span class="o">:</span> <span class="s2">"John-David"</span><span class="p">,</span> <span class="s2">"mathias"</span><span class="o">:</span> <span class="s2">"Mathias"</span><span class="p">,</span> <span class="s2">"kitcam"</span><span class="o">:</span> <span class="s2">"Kit"</span><span class="p">,</span> <span class="s2">"maddy"</span><span class="o">:</span> <span class="s2">"Maddy"</span><span class="p">});</span>
<span class="c1">// => [{"jdalton": "John-David", "mathias": "Mathias"}, {"kitcam": "Kit", "maddy": "Maddy"}]</span>
</pre></div>
</div>
<h3 id="groupBy">groupBy <code>Maddy.groupBy(callback, [context], object)</code></h3>
<p>Groups an <strong>object</strong>’s members using the criteria specified by the <strong>callback</strong>.</p>
<div><div class="highlight"><pre><span class="nx">Maddy</span><span class="p">.</span><span class="nx">groupBy</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">dish</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">dish</span><span class="p">;</span>
<span class="p">},</span> <span class="p">{</span>
<span class="s2">"John-David"</span><span class="o">:</span> <span class="s2">"lasagna"</span><span class="p">,</span>
<span class="s2">"Mathias"</span><span class="o">:</span> <span class="s2">"sushi"</span><span class="p">,</span>
<span class="s2">"Maddy"</span><span class="o">:</span> <span class="s2">"lasagna"</span><span class="p">,</span>
<span class="s2">"Kit"</span><span class="o">:</span> <span class="s2">"soup"</span><span class="p">,</span>
<span class="s2">"Sam"</span><span class="o">:</span> <span class="s2">"cinnamon rolls"</span><span class="p">,</span>
<span class="s2">"Joe"</span><span class="o">:</span> <span class="s2">"sushi"</span><span class="p">,</span>
<span class="s2">"Mark"</span><span class="o">:</span> <span class="s2">"sushi"</span>
<span class="p">});</span>
<span class="cm">/* => {</span>
<span class="cm"> "lasagna": {"John-David": "lasagna", "Maddy": "lasagna"},</span>
<span class="cm"> "sushi": {"Mathias": "sushi", "Joe": "sushi", "Mark": "sushi"},</span>
<span class="cm"> "soup": {"Kit": "soup"},</span>
<span class="cm"> "cinnamon rolls": {"Sam": "cinnamon rolls"}</span>
<span class="cm">} */</span>
</pre></div>
</div>
<script src="lib/maddy.js"></script>
</body>
</html>