tc39 / proposal-array-unique

ECMAScript proposal for Deduplicating method of Array
138 stars 7 forks source link

Does .unique() mutate the original array? #4

Closed Pokute closed 4 years ago

Pokute commented 4 years ago

README.md doesn't adequately convey whether Array.prototype.unique() modifies the array or whether it returns a new array.

  1. no parameter, it'll work as [...new Set(array)]; Seems to create a new array since it implies data.unique() instead of data = data.unique().

  2. one index-key parameter (Number, String or Symbol), it'll get values from each array element with the key, and then deduplicates the origin array based on these values; The "deduplicates the origin array" implies mutating the original array.

For case 3, the above applies.

Typical cases section doesn't give any hints either. It would help if there was a simple data-row with returned value in comment indicating whether it was either modified or not.

Finally, the TypeScript polyfill looks like it doesn't modify the original array.

Jack-Works commented 4 years ago

I think mutating the original array is a bad design. We should avoid it in new methods.

hax commented 4 years ago

We should make it clear in README that the method return a new array.

TechQuery commented 4 years ago

dfab433