Ad
  • Custom User Avatar

    Object.assign takes two arguments in this case.

    The first argument is the target (to which properties will be assigned), in this case Array.prototype
    The second argument is a source (from which to assign properties), in this case the methods specified in the instructions (square, cube, sum, etc)

    The properties (methods) from the source are applied to the target, and the target is returned. In this case the return value is not necessary but the target ie: Array.prototype is modified (mutated).

    This is how many libraries like lodash and others work, "under the hood".

  • Custom User Avatar

    Well here Array is an object and Object.assign does what it's name tells us, it assigns or say inserts the given properties to the given object.
    As here we are assigning those square, cube etc properties to the Array.prototype object.

    Hope you get it?
    else do let me know, I will give you some examples!

    BTW CLEVER code!

  • Custom User Avatar

    Can anyone tell me how is Object.assign() working here

  • Custom User Avatar
  • Custom User Avatar

    learned how to remove empty strings from array using filter(). thanks!