Ad
  • Custom User Avatar

    illegal, because null transform to empty str

  • Custom User Avatar

    Wrong. Here is the condition:
    flatten('a', ['b', 2], 3, null, [[4], ['c']]) // returns ['a', 'b', 2, 3, null, 4, 'c']

    This solution converts any item to string, so flatten('a', ['b', 2], 3, null, [[4], ['c']]) returns ['a', 'b', '2', '3', '', '4', 'c']

  • Custom User Avatar

    Maybe it's easier to imagine x = [];, then x.slice(). Or even ([]).slice. In all cases, it looks on the instance of the array for the slice method and, failing to find one, walks the prototype chain until it gets there. Hypothetically less performant but it's a constant time optimization and I think some or most compilers optimize for the autoboxing this involves.