Ad
  • Custom User Avatar

    This is a 6 kyu, not a total beginner kata, you should know how to sort and how builtin sort algorithms work.

  • Custom User Avatar

    You were taught wrong. The JS spec did not specify a stable sort until, as mentioned, Node 12.x, so using legacy Node versions, you have to take that into account. Teachers that overlooked this did you a disservice.

  • Custom User Avatar

    Fun challenge. For anyone whose solution times out, I would recommend rethinking your algorithm. It's tempting to think that you need to constantly iterate over each element of the array, but you actually don't.

  • Custom User Avatar

    Fun kata. The challenging part is thinking of an efficient way to check if a number is prime or not.

  • Custom User Avatar

    JavaScript won't divide very large numbers properly if you try to divide the ordinary way. Try figuring out if each substring coerced to a number is odd or not without dividing the entire number.

  • Custom User Avatar

    After looking through the solutions, I see that others have used JavaScript's built-in sort method with success. However, their usage is different from the way that I, and many other beginners, are probably taught.

    If I wanted to sort an array containing numbers in ascending numerical order, I learned to use sort like so:

    arr.sort((a, b) => a - b);

    My original solution used a modification of this that worked perfectly in VSCode with an up-to-date version of Node. However, it wouldn't work for every test case when attempting to pass this kata. Some randomly generated arrays would not sort properly in the kata's output, but they would sort properly when I used them in my program in VSCode.

  • Custom User Avatar

    Other people in these comments mentioned that they had the same problem with JavaScript. One of those people mentioned that this kata does not use Node v12 or greater, and the built-in sort method is unstable in earlier versions of Node.

    I originally wrote my solution using JavaScript's built-in sort method in VSCode using an up-to-date version of Node, and it worked perfectly. I even tested one of the randomly generated arrays that this kata gave me an error for. In VSCode, that array sorted properly using the built-in sort method.

    Because of this, I had to use my own bubble sort function instead of JavaScript's in order for this kata to pass my code.

  • Custom User Avatar

    If a homebrew bubble sort worked for you and library sort did not, it most probably means that sort was not applied correctly.

    What would be a reason to have sort at all if something as bad as bubble sort would work better that it?

  • Custom User Avatar

    As others mentioned, the JavaScript sort() method doesn't work properly for the 500 tests, so I had to use my own bubble sort function to get my code to pass. I definitely think this should be a 5 kyu problem. It was much more time-consuming to solve that other 6 kyu problems.