import jQuery from "../core.js";
import document from "../var/document.js";
import sort from "../var/sort.js";
+import splice from "../var/splice.js";
var hasDuplicate;
}
}
while ( j-- ) {
- results.splice( duplicates[ j ], 1 );
+ splice.call( results, duplicates[ j ], 1 );
}
}
}
}
Arrayish.prototype = {
- slice: [].slice,
- sort: [].sort,
- splice: [].splice
+ sliceForTestOnly: [].slice
};
var i, tests,
jQuery.each( tests, function( label, test ) {
var length = test.length || test.input.length;
- assert.deepEqual( jQuery.uniqueSort( test.input ).slice( 0, length ), test.expected, label + " (array)" );
- assert.deepEqual( jQuery.uniqueSort( new Arrayish( test.input ) ).slice( 0, length ), test.expected, label + " (quasi-array)" );
+ // We duplicate `test.input` because otherwise it is modified by `uniqueSort`
+ // and the second test becomes worthless.
+ assert.deepEqual( jQuery.uniqueSort( test.input.slice( 0 ) ).slice( 0, length ),
+ test.expected, label + " (array)" );
+ assert.deepEqual( jQuery.uniqueSort( new Arrayish( test.input ) ).sliceForTestOnly( 0, length ),
+ test.expected, label + " (quasi-array)" );
} );
} );