Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
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.
Fun kata. The challenging part is thinking of an efficient way to check if a number is prime or not.
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.
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.
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-insort
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.
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.