i = 0,
length = elems.length,
// jquery objects are treated as arrays
- isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || jQuery.isArray( elems ) ) ;
+ isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
// Go through the array, translating each of the items to their
if ( isArray ) {
});
test("map()", function() {
- expect(7);
+ expect(8);
same(
jQuery("#ap").map(function(){
});
equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
+ var nonsense = document.getElementsByTagName("asdf");
+ var mapped = jQuery.map( nonsense, function( v, k ){
+ return v;
+ });
+ equals( mapped.length, nonsense.length, "Map an empty array(-like) to a hash" );
+
var flat = jQuery.map( Array(4), function( v, k ){
return k % 2 ? k : [k,k,k];//try mixing array and regular returns
});