Ad
  • Default User Avatar

    Hi man! Can you tell us what's wrong with 'wkppvixoyxzzzzzzzzzzzz' result in this example?
    I also get the same result.

  • Custom User Avatar

    The ECMAScript standard doesn't specify and V8 (NodeJS, Chromium) doesn't guarantee stability, so this is expected.

    However, the longer random examples in this Kata appeared to break this pattern, and equivalent length strings were rearranged in the array after the sort method. I'm not able to explain this behaviour.

    I haven't looked at the source, so I'm just guessing, but probably the sorting algorithm used depends on the length of the array. Switching to unstable but faster one for larger array.

    ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].sort((a, b) => a.length - b.length);
    ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    
    ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a'].sort((a, b) => a.length - b.length);
    ['5', '0', '2', '3', '4', '1', '6', '7', '8', '9', 'a']
    

    Looks like in-place quicksort and insertion sort is used (v8/src/js/array.js#L709-L1002).

    // Insertion sort is faster for short arrays.
    if (to - from <= 10) {
      InsertionSort(a, from, to);
      return;
    }
    
  • Default User Avatar

    Interesting Kata. I've discovered a quirk about the javacript Array.prototype.sort method, that sometimes re-arranges array items in an unexpected fashion. For example, when implementing the following code, the expected result is returned.

    ['abc', 'def', 'ghi'].sort((a, b) => a.length - b.length).join('') // => 'abcdefghi'
    

    However, the longer random examples in this Kata appeared to break this pattern, and equivalent length strings were rearranged in the array after the sort method. I'm not able to explain this behaviour.

  • Default User Avatar

    Post a question not an issue.The tests are the same in all languages and 5956 guys passed the kata!
    There are no errors in the tests.
    Please re-read the description.

  • Custom User Avatar

    At the test: ['it', 'wkppv', 'ixoyx', '3452', 'zzzzzzzzzzzz'],3
    Im returning "wkppvixoyxzzzzzzzzzzzz" but it expects "ixoyx3452zzzzzzzzzzzz"
    The three largest strings are "wkppv", "ixoyx" and "zzzzzzzzzzzz"
    Isn't this an error, or did i misunderstand the Kata.

  • Custom User Avatar

    Did you see hint?

  • Custom User Avatar

    Hmm,:?, I actually had overlooked the puzzle tag. I have updated and added it.

  • Custom User Avatar

    Seen and approved! Thank you!

  • Default User Avatar

    When the score is 257,why allergies are eggs instead of cats and eggs?
    I was confused about how the score make up?
    Why the score can be 1000?

  • Custom User Avatar

    PHP version!Cheers

  • Custom User Avatar

    I concur, it should be used more often for this kind of neat katas :)

  • Custom User Avatar

    @BrianLusina you have made cool kata,thanks!

    IMO add puzzle tag ;D

  • Custom User Avatar

    Noted. Crystal translation approved. :+1:

  • Custom User Avatar

    Nope, just the same error message and the same type of exception is thrown for each data type that is not an integer.

  • Custom User Avatar

    Noted and updated. Thank you

  • Loading more items...