Skip to content

Latest commit

 

History

History
22 lines (21 loc) · 1.28 KB

File metadata and controls

22 lines (21 loc) · 1.28 KB

TODO: Write solution to main task Module 2!

  1. Set the O variable to be an Object cast of the this value (array the function was used on)
  2. Set the len variable to be the length of the O Object, which is an ArrayLike (essentially a list).
  3. Check the callbackfn passed into the function, if it is not callable (if it essentially isn't a function) throw an TypeError
  4. Set the value k to be 0
  5. Create a list titled groups
  6. Iterate len times:
    1. Convert K into a String in order to use it to get the aproporiate Value from O
    2. Set kValue to be the value located at k index in the list
    3. Use the callbackfn defined in the function parameter to convert the kValue to it's group key. Put that value into variable propertyKey
    4. Use the AddValueToKeyedGroup function defined below to add the value into the list groups
    5. Increment k
  7. Create an ordinary JavaScript Object, which inherits from Object and put it into the variable obj.
  8. For each (key, [value]) in groups:
    1. Create an array from the elements corresponding to the current key
    2. Create a property on the ordinary object created on step 7, if error: throw said error.
    3. Return the created object