Hi, the indexOf() method searches the array for the specified item, and returns its position.
To sort numbers in array descending good method is:
[40, 100, 1, 5, 25, 10].sort((a,b) => b - a),
as simple sort() method will sort values as strings, not as numbers.
Good explanation here of the trick is here: https://www.w3schools.com/js/js_array_sort.asp
In my case, I use DENS array (where letters are presorted manually) to provide an order in which I would like letters to be sorted.
Insead of comapring values of b & a, I'm comparing indexes of b & a in my custom DENS array.
Hope this helps.
Hard to tell as you don't state which language you're using. But for something like Javascript the kata has already been completed by over 18k persons.
Please use markdown tags to format your code or it is very discomfortable to read: how-to-format-code-in-markdown.
Hi, the indexOf() method searches the array for the specified item, and returns its position.
To sort numbers in array descending good method is:
[40, 100, 1, 5, 25, 10].sort((a,b) => b - a),
as simple sort() method will sort values as strings, not as numbers.
Good explanation here of the trick is here: https://www.w3schools.com/js/js_array_sort.asp
In my case, I use DENS array (where letters are presorted manually) to provide an order in which I would like letters to be sorted.
Insead of comapring values of b & a, I'm comparing indexes of b & a in my custom DENS array.
Hope this helps.
[...string]
is justArray.from(string)
. That'll break up the string into an array of single characters, which is a bear to type in.There are actually quite some places where JS will handle a string as an array of characters.
idexOf is something new to me. Can you spare time to explain how your sort works?
can you please explain the returned arrays please?
This comment is hidden because it contains spoiler information about the solution
Came here to see how many others said this. Maybe it's harder in other languages? I did it in Python and passed on my first attempt.
Don't post solutions in Discourse, please.
This comment is hidden because it contains spoiler information about the solution
No test is broken, they're fine. Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
1 test in JavaScript is broken.
"1 should equal 0"
The unique number is the first item (like the test says). Print the input.
Can someone explain what the test condition here is? My code seems to fail only in this
The first item
1 should equal 0
there are over 18 thousand solves in javascript (your language), so yeah. the kata is not broken.
Hard to tell as you don't state which language you're using. But for something like Javascript the kata has already been completed by over 18k persons.
Loading more items...