Ad
  • Default User Avatar

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

  • Custom User Avatar

    Hey Everyone,

    I am new to programming. I approached this kata in javascript with aim to practive object oriented programming and ES6 classes. I spent some time on this kata and I was supper proud with what I came up with. Unfortunatelly my solution did not pass the tests. The one thing I was missing / doing different than the solutins I found here, was to set the direction property on the Array object through the dot notation in stead of the Object.defineProperty method. I played around with both approaches and whenever logging my object to the console I saw the same things in both cases. Could someone explain why this assigning the dir property through the dot notation fails this kata tests? What is the difference when I use the Object.defineProperty function simply specyfing the value in the descriptor?
    Your help would be very much appreciated :D

  • Default User Avatar

    Object.defineProperty is recomending method on JS ? i'm first use

  • Custom User Avatar

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

  • Default User Avatar

    The use of the init parameter is not tested. I see at least one solution passed where the numeric value was inserted, while the behaviour of the Array constructor is to set the length of the array to that value.

    In the same line you may want to conform with the Array constructor behaviour when mutliple arguments are given, in which case they are inserted. And then it would be good to also require (and test!) that the Array is sorted at that very moment as well.

  • Custom User Avatar

    You changed the Description, but did you change the tests?

     #pop
     should remove a single value from the end of array
     should return the new array
    Expects array, got: 6
    Completed in 1ms
    Completed in 2ms
     #shift
     should remove a single value from the start of array
     should return the new array
    Expects array, got: 1
    Completed in 1ms
    

    You're not afraid to invalidate existing solutions are you ?!? :yum:

  • Custom User Avatar

    Fixed it up.

  • Custom User Avatar

    I was having the same thoughts. I'm leaning toward making it more in line with Array

  • Custom User Avatar

    I'm not sure I like the change to pop and shift, where they do not return the removed value.

    Returning this ( sorted or otherwise ) has the advantage of enabling chaining, but this has the disadvantage of losing the removed value entirely and making the four SortedArray methods very, very much alike each other.

    Maybe you should invent a version of SortedArray that's more unlike Array. ( Maybe only in a next version of this kata .. )

  • Custom User Avatar

    Thought:

    "Currently, that is unspecified" would be the correct answer. Inventing a specification might be a good idea, but there is no reason this must be the Array.prototype behaviour. Or the reference solution behaviour.

  • Custom User Avatar

    Currently, it returns back an empty array and has no effect. It might be a good idea to bring this inline with Array.prototype and have it return undefined. Thoughts?

  • Custom User Avatar

    What is the behavior of pop/shift on an empty array?

  • Custom User Avatar

    For this version of the kata, no. I'm going to be posting an advanced version of this soon where it will be different.

  • Custom User Avatar

    Is there a difference in behavior between unshift and push?

  • Custom User Avatar

    Not an issue.

  • Loading more items...