prototype: Array.prototype.uniq optimization. Closes #7417.
This commit is contained in:
parent
74596ac289
commit
6eca3f0eea
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Array.prototype.uniq optimization. Closes #7417. [Christophe Porteneuve]
|
||||
|
||||
* String.prototype.endsWith should not fail on multiple occurrences. Closes #7416. [Christophe Porteneuve]
|
||||
|
||||
* Add Form.Methods.request as a convenience method for serializing and submitting a form via Ajax.Request to the URL in the form's action attribute. [sam]
|
||||
|
|
|
@ -68,9 +68,11 @@ Object.extend(Array.prototype, {
|
|||
return this.length > 1 ? this : this[0];
|
||||
},
|
||||
|
||||
uniq: function() {
|
||||
return this.inject([], function(array, value) {
|
||||
return array.include(value) ? array : array.concat([value]);
|
||||
uniq: function(sorted) {
|
||||
return this.inject([], function(array, value, index) {
|
||||
if (0 == index || (sorted ? array.last() != value : !array.include(value)))
|
||||
array.push(value);
|
||||
return array;
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -127,6 +127,7 @@
|
|||
assertEnumEqual([1], [1].uniq());
|
||||
assertEnumEqual([], [].uniq());
|
||||
assertEnumEqual([0, 1, 2, 3], [0, 1, 2, 2, 3, 0, 2].uniq());
|
||||
assertEnumEqual([0, 1, 2, 3], [0, 0, 1, 1, 2, 3, 3, 3].uniq(true));
|
||||
}},
|
||||
|
||||
testWithout: function(){ with(this) {
|
||||
|
|
Loading…
Reference in New Issue