Skip to content

Commit 9685f8a

Browse files
authored
jQuery.map:jQuery.uniqueSort: Accept array-like input, fix typos
Changes: * `jQuery.map`: Accept array-like input * `jQuery.uniqueSort`: Accept array-like input, fix typos. Apart from array-like inputs being officially allowed in `jQuery.uniqueSort` now, in a few places in examples it used to be referred to as `unique` instead of `uniqueSort`. Closes gh-1214
1 parent a9dbdbc commit 9685f8a

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

entries/jQuery.map.xml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<title>jQuery.map()</title>
44
<signature>
55
<added>1.0</added>
6-
<argument name="array" type="Array">
7-
<desc>The Array to translate.</desc>
6+
<argument name="array" type="ArrayLikeObject">
7+
<desc>The Array or an Array-like object to translate.</desc>
88
</argument>
99
<argument name="callback" type="Function">
1010
<argument name="elementOfArray" type="Object" />
@@ -16,7 +16,7 @@
1616
<signature>
1717
<added>1.6</added>
1818
<argument name="object" type="Object">
19-
<desc>The Object to translate.</desc>
19+
<desc>The non-Array-like Object to translate.</desc>
2020
</argument>
2121
<argument name="callback" type="Function">
2222
<argument name="propertyOfObject" type="Object" />
@@ -28,16 +28,13 @@
2828
<desc>Translate all items in an array or object to new array of items.</desc>
2929
<longdesc>
3030
<p>If you wish to process a jQuery object — for example, <code>$('div').map( callback );</code> — use <a href="/map/">.map()</a> instead. </p>
31-
<p>The <code>$.map()</code> method applies a function to each item in an array or object and maps the results into a new array. <strong>Prior to jQuery 1.6</strong>, <code>$.map()</code> supports traversing <em>arrays only</em>. <strong>As of jQuery 1.6</strong> it also traverses objects.</p>
32-
<p>Array-like objects &#x2014; those with a <code>.length</code> property <em>and</em> a value on the <code>.length - 1</code> index &#x2014; must be converted to actual arrays before being passed to <code>$.map()</code>. The jQuery library provides <a href="/jQuery.makeArray/">$.makeArray()</a> for such conversions.</p>
31+
<p>The <code>$.map()</code> method applies a function to each item in an array or object and maps the results into a new array. <strong>Prior to jQuery 1.6</strong>, <code>$.map()</code> supports traversing <em>arrays and array-like objects only</em>. <strong>As of jQuery 1.6</strong> it also traverses objects.</p>
32+
<p>Array-like objects &#x2014; those with a <code>.length</code> property <em>and</em> a value on the <code>.length - 1</code> index &#x2014; may be passed to <code>$.map()</code>.</p>
3333
<pre><code>
34-
// The following object masquerades as an array.
34+
// The following object is array-like.
3535
var fakeArray = { "length": 2, 0: "Addy", 1: "Subtracty" };
3636

37-
// Therefore, convert it to a real array
38-
var realArray = $.makeArray( fakeArray )
39-
40-
// Now it can be used reliably with $.map()
37+
// It can be used reliably with $.map()
4138
$.map( realArray, function( val, i ) {
4239
// Do something
4340
});

entries/jQuery.uniqueSort.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
<title>jQuery.uniqueSort()</title>
44
<signature>
55
<added>1.12-and-2.2</added>
6-
<argument name="array" type="Array">
7-
<desc>The Array of DOM elements.</desc>
6+
<argument name="array" type="ArrayLikeObject">
7+
<desc>The Array or an Array-like object of DOM elements.</desc>
88
</argument>
99
</signature>
10-
<desc>Sorts an array of DOM elements, in place, with the duplicates removed. Note that this only works on arrays of DOM elements, not strings or numbers.</desc>
10+
<desc>Sorts an array or an array-like object of DOM elements, in place, with the duplicates removed. Note that this only works on arrays/array-likes of DOM elements, not strings or numbers.</desc>
1111
<longdesc>
12-
<p>The <code>$.uniqueSort()</code> function searches through an array of objects, sorting the array, and removing any duplicate nodes. A node is considered a duplicate if it is the <em>exact same</em> node as one already in the array; two different nodes with identical attributes are not considered to be duplicates. This function only works on plain JavaScript arrays of DOM elements, and is chiefly used internally by jQuery. You probably will never need to use it.</p>
12+
<p>The <code>$.uniqueSort()</code> function searches through an array or an array-like object of DOM elements, sorting the array/array-like, and removing any duplicate nodes. A node is considered a duplicate if it is the <em>exact same</em> node as one already in the input; two different nodes with identical attributes are not considered to be duplicates. This function only works on plain JavaScript arrays/array-like objects of DOM elements, and is chiefly used internally by jQuery. You probably will never need to use it.</p>
1313
<p>Prior to jQuery 3.0, this method was called <code><a href="/jQuery.unique/">jQuery.unique()</a></code>.</p>
1414
<p>As of jQuery 1.4 the results will always be returned in document order.</p>
1515
</longdesc>
1616
<example>
1717
<desc>Removes any duplicate elements from the array of divs.</desc>
1818
<code><![CDATA[
19-
// unique() must take a native array
19+
// uniqueSort() must take a native array
2020
var divs = $( "div" ).get();
2121
2222
// Add 3 elements of class dup too (they are divs)
2323
divs = divs.concat( $( ".dup" ).get() );
24-
$( "div" ).eq( 1 ).text( "Pre-unique there are " + divs.length + " elements." );
24+
$( "div" ).eq( 1 ).text( "Pre-uniqueSort there are " + divs.length + " elements." );
2525
2626
divs = jQuery.uniqueSort( divs );
27-
$( "div" ).eq( 2 ).text( "Post-unique there are " + divs.length + " elements." )
27+
$( "div" ).eq( 2 ).text( "Post-uniqueSort there are " + divs.length + " elements." )
2828
.css( "color", "red" );
2929
]]></code>
3030
<css><![CDATA[

0 commit comments

Comments
 (0)