6 kyu

Arrays are Objects

Description
Loading description...
Arrays
Fundamentals
  • Please sign in or sign up to leave a comment.
  • ejini战神 Avatar

    The chaining methods are not tested completely. See this solution

  • trashy_incel Avatar

    The sample tests use assertSimilar while the submission tests use assertDeepEquals. These assertions have slightly differing semantics: extending Array, I pass the full tests but I fail the getSplit sample test:

    Expected: 
    '{ pass: [ \'a\', \'b\', \'c\' ], fail: [ 1, 2, 3 ] }'
    , instead got: 
    '{ pass: MagicArray [ \'a\', \'b\', \'c\' ],\n  fail: MagicArray [ 1, 2, 3 ] }'
    
  • farhanaditya Avatar

    JS: Node v14 should be used along with its appropiate assertion tools (Mocha + Chai). Refer to this and this

  • FArekkusu Avatar

    eq: function(n) - Return an array with all methods, only containing the eq item...

    This description makes zero sense; the expected behavior is extracting the n'th element of an array.

  • FArekkusu Avatar

    Your task is to make an object and add to it the following methods...

    This is not enforced.

  • bojan88 Avatar

    I can't get passed "getSplit" test. My split object looks like this:

    {pass: magicArray, fail: magicArray}

    Am I missing something or the tests have issues? I can see that when instance of magicArray is compared with instance of Array, the test suite is creating strings which contain only array elements and then comparing those strings. When comparing objects with magicArrays, it's creating a string out of object and not checking if properties are arrays.

    • JohanWiltink Avatar

      Did you trip over enumerability of methods? Or do you have magicArrays that aren't arrays?

    • bojan88 Avatar

      They are arrays, but with extra methods which are ignored when assertSimilar arguments are arrays. When you pass an object containing magicArray to assertSimilar, those extra methods from fn object are not ignored Here is the fail message:

      Expected: '{ pass: [ \'a\', \'b\', \'c\' ], fail: [ 1, 2, 3 ] }', instead got: '{ pass: \n [ \'a\',\n \'b\',\n \'c\',\n getFiltered: [Function: getFiltered],\n getRejected: [Function: getRejected],\n getSplit: [Function: getSplit],\n count: [Function: count],\n double: [Function: double],\n multiply: [Function: multiply],\n first: [Function: first],\n last: [Function: last],\n eq: [Function: eq] ],\n fail: \n [ 1,\n 2,\n 3,\n getFiltered: [Function: getFiltered],\n getRejected: [Function: getRejected],\n getSplit: [Function: getSplit],\n count: [Function: count],\n double: [Function: double],\n multiply: [Function: multiply],\n first: [Function: first],\n last: [Function: last],\n eq: [Function: eq] ] } '

    • klicks Avatar

      I'm getting this failure as well, if the pass/fail properties are not magicArrays then the chainable tests will fail, otherwise the getSplit test will fail. Any suggestions?

      EDIT: durr, just needed to define the method props as non-enumerable :)

  • JohanWiltink Avatar

    In double and multiply :

    This should change the values of the source array.

    If this is meant to imply the method should mutate the array they're called on, it's not tested that way (and not everyone implements it that way).
    Either way, it's unclear.

  • ZozoFouchtra Avatar

    Shouldn't testArrayTwo.multiply(2).first().double().double() returns [2, 2, 2, 2] instead of [2, 2, 2] ?

    ( [2].double() -> [2,2], then [2,2].double() -> [2,2,2,2])

    • MentalAtom Avatar

      Yes, it does so in the test cases - I caught that when I was testing but missed in the description.

      That's now updated in the example. Thanks, good spot!