Ad
  • 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.

  • Custom User Avatar

    I tried that, but the test says

    TypeError: Cannot call method 'toArray' of null
    at Test.it
    at Test.describe

    If I use Cons(null, null) I get this error:

    TypeError: Cannot call method 'toArray' of undefined
    at Test.it
    at Test.describe

  • Custom User Avatar

    Based on the link to the algebraic data type documentation, I think Cons.fromArray([]) should return null, but I wasn't positive.

  • Custom User Avatar

    What should Cons.fromArray([]) return?

    null

    or

    new Cons(null, null)

    or something else?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution