Ad
  • Custom User Avatar
  • Custom User Avatar
    1. The filter method for arrays receives up to 3 arguments (in the following order) element, index, array and returns a filtered array in which the function passed in returns true
    2. The arrow => denotes an arrow function, introduced in ES6, the newest specification for Javascript to date. The behaviour and usage of arrow functions is nearly identical to that of ordinary functions - the notations can be used interchangeably 99% of the time
    3. The three dots prefixed to a variable ... adds all the items in a specified list (e.g. function arguments, an array or even a string) into an array.

    Hope this helps :)

  • Custom User Avatar

    Could you explain how this line works?

    copy = [...copy.filter((a,b)=>b>0), ...copy.filter((a,b)=>b==0)];

    Thanks!