Skip to content
Richard L. Hudson edited this page Feb 25, 2014 · 1 revision

###Array.prototype.scatterPar ( indices, defaultValue=undefined, callbackfn=undefined, length=this.length, thisArg = undefined )

scatterPar returns a result array of length where result[indices[i]] = source[i]. If indices contain duplicates then the value returned by callbackfn is used to populate
result[indices[i]]. Missing elements in the result are initialized to defaultValue.

callbackfn should be a function that accepts two arguments and returns a value. The result value is placed at the index specified. If a thisArg parameter is provided, it will be used as the this value for each invocation of callbackfn. If it is not provided, undefined is used instead.

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

The range of elements processed by filter is set before the first call to callbackfn. Elements which are appended to the array after the call to filter 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 filter visits them; elements that are deleted after the call to filter begins and before being visited are not visited.

When the scatterPar method is called with one to five arguments, the following steps are taken:

  1. Let O be the result of calling ToObject passing the this value as the argument.
  2. ReturnIfAbrupt(O).
  3. Let lenValue be the result of Get(O, "length").
  4. Let len be ToLength(lenValue).
  5. ReturnIfAbrupt(len).
  6. If defaultValue is not supplied let defaultValue be undefined.
  7. Let resolveConflict be IsCallable(callbackfn).
  8. If thisArg was supplied, let T be thisArg; else let T be undefined.
  9. Let Conflict be a new empty List.
  10. If O is an exotic Array object, then
    1. Let C be Get(O, "constructor").
    2. ReturnIfAbrupt(C).
    3. If IsConstructor(C) is true, then
      1. Let thisRealm be the running execution context’s Realm.
      2. If thisRealm and the value of C’s Realm internal slot are the same value, then
        1. Let A be the result of calling the Construct internal method of C with an argument list containing the single item length.
  11. If A is undefined, then
    1. Let A be the result of the abstract operation ArrayCreate with argument length.
  12. ReturnIfAbrupt(A).
  13. For each array index value k between 0 and length – 1
    1. Let A[k] = defaultValue
  14. In arbitrary order for each array index value k between 0 and len - 1 
    1. Let Pk be ToString(k).
    2. Let kPresent be the result of HasProperty(O,_ Pk_).
    3. ReturnIfAbrupt(kPresent).
    4. If kPresent is true, then
      1. Let kValue be the result of Get(O,_ Pk_).
      2. ReturnIfAbrupt(kValue).
    5. Let iPresent be the result of HasProperty(I, Pk).
    6. ReturnIfAbrupt(iPresent).
    7. If iPresent is true, then
      1. Let iValue be the result of Get(I, Pk).
    8. ReturnIfAbrupt(iValue).
    9. Let isConflict be the result of HasProperty(Conflict, Pk).
    10. ReturnIfAbrupt(isConflict).
    11. If isConflict is true, then
      1. If resolveConflict is not true then throw a RangeError exception
      2. Let oldValue be the result of Get(A, Pk).
      3. Let newValue be the result of Get(A, Pk).
      4. Let kValue be the result of calling the Call internal method of callbackfn with T as thisArgument and a List containing oldValue, and newValues argumentsList.
    12. If isConflict is false then
      1. Let status be the result of SetProperty(_Conflict, Pk).
      2. ReturnIfAbrupt(isConflict).
    13. ReturnIfAbrupt(kValue).
    14. Let status be the result of CreateDataPropertyOrThrow (A, ToString(iValue), kValue_).
    15. ReturnIfAbrupt(status).
  15. Return A.

The length property of the scatterPar method is 1.

NOTE Whether the scatterPar function can be applied successfully to an exotic object that is not an Array is implementation-dependent.

Clone this wiki locally