What [1, , 2, , , 2, 1].unique() should return?
At least there are three options:
- Treat empty items as
undefined, so returns [1, undefined, 2].
This matches what [...new Set(arr)] do as README, but I suppose it's not intentional. Note if unique(f), f would be called on every empty items as undefined, (or called with no param?) (To avoid runtime error, if f is a key, I guess it should be treat as x => x?.[key])
- Skip all empty items and keep them, so returns
[1, , 2, , , ,]
- Skip all empty items and drop them, so returns
[1, 2]
Personally I prefer the last option.
What
[1, , 2, , , 2, 1].unique()should return?At least there are three options:
undefined, so returns[1, undefined, 2].This matches what
[...new Set(arr)]do as README, but I suppose it's not intentional. Note ifunique(f),fwould be called on every empty items asundefined, (or called with no param?) (To avoid runtime error, iffis a key, I guess it should be treat asx => x?.[key])[1, , 2, , , ,][1, 2]Personally I prefer the last option.