diff --git a/index.html b/index.html index f7a7b08..d96dd1d 100644 --- a/index.html +++ b/index.html @@ -2261,9 +2261,10 @@

2.1 Array.prototype.groupBy ( callbackfncallbackfn is called with three arguments: the value of the element, the index of the element, and the object being traversed.

groupBy does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn.

The range of elements processed by groupBy is set before the first call to callbackfn. Elements which are appended to the array after the call to groupBy begins will not be visited by callbackfn. If existing elements of the array are changed their value as passed to callbackfn will be the value at the time groupBy visits them; elements that are deleted after the call to groupBy begins and before being visited are not visited.

+

The return value of groupBy is an object that does not inherit from Object.prototype.

When the groupBy method is called with one or two arguments, the following steps are taken:

-
  1. Let O be ? ToObject(this value).
  2. Let len be ? LengthOfArrayLike(O).
  3. If IsCallable(callbackfn) is false, throw a TypeError exception.
  4. Let k be 0.
  5. Let obj be ! OrdinaryObjectCreate(%Object.prototype%).
  6. Assert: obj is an extensible ordinary object with no own properties.
  7. Repeat, while k < len
    1. Let Pk be ! ToString(k).
    2. Let kValue be ? Get(O, Pk).
    3. Let propertyKey be ? ToPropertyKey(? Call(callbackfn, thisArg, « kValue, k, O »)).
    4. Let seen be ? HasOwnProperty(obj, propertyKey).
    5. If seen is true, then
      1. Let arr be ! Get(obj, propertyKey).
    6. Else
      1. Let arr be ? ArraySpeciesCreate(O, 0).
      2. Perform ! CreateDataPropertyOrThrow(obj, propertyKey, arr).
    7. Perform ? Call(%Array.prototype.push%, arr, kValue).
    8. Set k to k + 1.
  8. Return obj.
+
  1. Let O be ? ToObject(this value).
  2. Let len be ? LengthOfArrayLike(O).
  3. If IsCallable(callbackfn) is false, throw a TypeError exception.
  4. Let k be 0.
  5. Let obj be ! OrdinaryObjectCreate(null).
  6. Assert: obj is an extensible ordinary object with no own properties.
  7. Repeat, while k < len
    1. Let Pk be ! ToString(k).
    2. Let kValue be ? Get(O, Pk).
    3. Let propertyKey be ? ToPropertyKey(? Call(callbackfn, thisArg, « kValue, k, O »)).
    4. Let seen be ? HasOwnProperty(obj, propertyKey).
    5. If seen is true, then
      1. Let arr be ! Get(obj, propertyKey).
    6. Else
      1. Let arr be ? ArraySpeciesCreate(O, 0).
      2. Perform ! CreateDataPropertyOrThrow(obj, propertyKey, arr).
    7. Perform ? Call(%Array.prototype.push%, arr, kValue).
    8. Set k to k + 1.
  8. Return obj.
Note 2

The groupBy function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.

diff --git a/spec.emu b/spec.emu index 5390d35..1cf3a80 100644 --- a/spec.emu +++ b/spec.emu @@ -30,6 +30,7 @@ location: https://tc39.es/proposal-array-grouping/

_callbackfn_ is called with three arguments: the value of the element, the index of the element, and the object being traversed.

`groupBy` does not directly mutate the object on which it is called but the object may be mutated by the calls to _callbackfn_.

The range of elements processed by `groupBy` is set before the first call to _callbackfn_. Elements which are appended to the array after the call to `groupBy` begins will not be visited by _callbackfn_. If existing elements of the array are changed their value as passed to _callbackfn_ will be the value at the time `groupBy` visits them; elements that are deleted after the call to `groupBy` begins and before being visited are not visited.

+

The return value of `groupBy` is an object that does not inherit from _Object.prototype_.

When the `groupBy` method is called with one or two arguments, the following steps are taken:

@@ -37,7 +38,7 @@ location: https://tc39.es/proposal-array-grouping/ 1. Let _len_ be ? LengthOfArrayLike(_O_). 1. If IsCallable(_callbackfn_) is *false*, throw a *TypeError* exception. 1. Let _k_ be 0. - 1. Let _obj_ be ! OrdinaryObjectCreate(%Object.prototype%). + 1. Let _obj_ be ! OrdinaryObjectCreate(null). 1. Assert: _obj_ is an extensible ordinary object with no own properties. 1. Repeat, while _k_ < _len_ 1. Let _Pk_ be ! ToString(_k_).