Retired
-Reverse it, quickly! (retired)
3,444 of 3,446avadakedavra
Loading description...
Arrays
Puzzles
Restricted
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Retired as per following discussion: https://github.com/codewars/content-issues/issues/158
I found the bag For code weirdReverse=a=>a.sort(_=>-1) i got error weirdReverse([1,2,3,4,5]) Should return [5,4,3,2,1] Array must be reversed - Expected: '[5, 4, 3, 2, 1]', instead got: '[1, 2, 3, 4, 5]', but my code RETURNS right variant in my IDE.
Hi. Ok, I found this one by chance, but I don't really understand how it works under the hood. Does this syntax define the first element as the maximum of the array with indices from
0
ton-1
, then the second element as the maximum of the subarray with indices from1
ton-1
, and so on up ton-1
? Could someone please explain/confirm it ?This is what I've tried, still to long: weirdReverse=a=>a.map(a.pop,[... a])
Please remove this kata, it's the worst one I've seen on Codewars. The only one accepted solution (with 28-char length of code) is simply incorrect, doesn't work in Chrome console. This solution only works when we change compare function output to -1, which results in 29-char length of code so it fails the tests. For learners kata like this only creates unnecessary confusion. Waste of time. Remove it.
In Chrome you don't have the same JS implementation that here, we use NodeJS. If you don't like a kata, it's easy: move on, there are thousands more.
OK fair enough, being a newbie I didn't realize various implementations make such a difference in code output. So far I've been thinking "If it doesn't work in my browser, it must be wrong". I guess I was wrong. Codewars should be more beginner-friendly nevertheless... Think of folks like me who don't even know what "implementation" is:-), barely started the adventure of coding.
This kata isn't compatible with newer Node versions as it relies on a specific behavior of
.sort
in Node v8.Duplicated issue.
The algorithms have already changed. 13 characters would be relevant;
what?
This is the worst kata I've experienced. You either know the expected solution or you don't. Nothing to learn from this.
Out of curiosity, what is the state inbetween "Knowing" and "Not Knowing"?
What I mean is that there's no way to solve this in a better or worse way. You either solve it in the one-and-only way or you won't be able to solve it at all. There's no middle-ground. There's nothing to learn from looking at other solutions and seeing how they compare to yours, as all the solutions are the same. You won't come back to this problem on another day to see if you could do better. I think this problem completely misses the spirit of katas.
Maybe. But then, this is how every Puzzle kata works, too. Then again, if the solution can be researched (e.g. language tricks that lead to a better understanding of the internals) then there is merit after all.
Well, I haven't really come across many katas in puzzle category. So I made a search and looked into several examples, but I have to admit I saw no clear pattern. There were some code-golf problems, but also a whole lot of other things ranging from counting even numbers to implementing MineSweeper. Importantly I noticed no other problems where only one solution would be applicable.
I also have no idea how to research for a solution to this problem. I guess one could google for "shortest code for reversing array in JavaScript", but that's just googling for the exact answer.
But most importantly, as many others have commented, a correct solution to this kata is actually not even possible - according to description the solution should reverse an array containing any types, but the .sort() solution will fail when the array contains undefined values.
Why does
_ => _.sort(r)
.work. I get the normal method used but shouldn't this break as r is undefined / is this some global variable defined that some solutions are using ?
This comment has been hidden.
No response after 2 months, closing.
"Oh easy! I can easily do it in less than 24 characters! :D It suffices to write f=... oh wait... weirdReverse ... O__o ...You... son of a... ...Tr0ll!... >:("
OK "Done", now ^^
For Anyone wondering how it works, I think it has everything to do with the verson of Node you are running, like when I ran it here on CodeWars (node v8), it did reverse the array. But when I tried the same on my local machine (node v12), it did not flip it. I also tried this on other online compilers, both version 8 and 12 and found the results same as what I described. I think we just may be exploiting a bug of the version 8 node. I sure might be wrong, so anyone who has another theory, please comment down.
You're right about that.
Anyway, a
suggestion
tag means a suggestion for the kata/author/contributors, not users. Closing.The "solution" is based on "implementation-defined" Array.prototype.sort behaviour. Check ecma-262 if you don't believe me, especially the part which defines "consistent comparison function". It's wrong on semantic level and basically useless as part of any training.
"Solution" doesn't works in my Chrome.
This kata is unusual in that it requires using "bad practice" programming of relying on the implementation details that vary between JavaScript engines.
Probably, this kata is only available for JavaScript because of this.
As of 2020.09 it works on Firefox, but not Chrome, Safari or Node 12. It does work with the older version of Node used by the kata.
SEE: (MDN page for Array.prototype.sort)[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort]
By always returning 1 from the sort comparator regardless of the (a,b) arguments, we are returning inconsistent results which means the sort order is undefined (i.e. implementation dependent).
This is true for ES6 and ES2020. ES2019 made the big change to Array.prototype.sort to be a stable sort and it looks like some implmementations changed that broke previous behavior around the undefined sort order.
This is the first kata I've encountered that explicitly disavows correct, reliable code within spec.
I think it makes sense to annotate katas that depend on such unstable, bad practices to better inform learners that the kata should not to be used as a role model of good problem solving or coding practices.
For me, the solution is only working here. Not in the chrome's console. It works when I change the 1 with a negative 1.
This comment has been hidden.
This comment has been hidden.
does it run in the kata context? Yes it does. => no issue here.
The only issue here is your knowledge about contexts of executions... like... node versions...? x/
Ok. Sorry.
The solution only works up to version 11 of the node
I fail to see why is this a problem when you can only select up to Node 8 in this kata.
not an issue (of the kata)
The solutions provided are flawed and incorrect by way of the described requirements of the array containing data of any type:
yields proof:
In other words, this challenge is impossible to solve at the current character limit.
1593 completions
What do you mean?
This comment has been hidden.
lol how do these solutions work? they dont do anything in console, only if you return -1 instead of 1, then it works
As far as I understand, there's only one acceptable solution and it doesn't actually work for all arrays. I'd prefer for the length requirement to be a bit longer and encourage a more robust solution.
Nope, not happening
4 kyu? It's so easy. Seems liek 8 kyu practically
how come ?
Seriously, 4 kyu? It is so easy.
stop flexing
This comment has been hidden.
This comment has been hidden.
I can't think of anything else !!! :D
I give up !!!! NO .................
The count includes the function name and you can typically save a char omitting the semicolon from the end
This comment has been hidden.
Have you found a solution that would work with that input and still being in the code length limit? Maybe the tests are ok for that.
I think this fact was already known at the time it was approved. Anyway, as it often happens with golfing katas, it expects a certain type of solution. If you have something more general, feel free to submit it here https://www.codewars.com/kata/the-soul-of-wit-reverse-an-array ;-)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
changed the comment content bcoz I could not delete it. That trick won't work for this problem but it is good anywhere else since it works for all types of arrays
Sorry, but... how did you control the number of characters?I can't know how you did it watching your test. I have created a Kata and a need to checkout the characters. Thank's mate. :)
There's a file called
solution.txt
in the sandbox' home, just read with with thefs
moduleThis comment has been hidden.
It's all what you write in Solutions panel.
Ah ok! Thank you!
Can't love this kata anymore!!!
The cheat code PASSED:: return (I haven't given cause u understand) getting rampant, needs urgent attention . Use conditions to tackle the cheating. Maybe a simple regular expression to match the solution in preloaded
This comment has been hidden.
This comment has been hidden.
fixed test cases are correct. limit is less than 29(or <=28), you are only one step away 8)
29 characters not passing , it is cruel avadakedavra :(((
This comment has been hidden.
Post your solution, mark your post as having spoiler content (the checkbox below). Are you sure you don't have a newline or a space there?
This comment has been hidden.
Is the task to write a reverse array code with 29 chars max length ? I see that this length is for all function code with function name included ('weirdReverse'). So remained length is 29 - length('weirdReverse') = 17 chars. Am I right ? Thanks in advance.
Yes.
29 chars
refers to the entirety of your code.I think.....can we change a function name link "w"?
My next shortest is 35 chars and it should work for any input. Is 35 small enough for another kata?
33 is possible.
This comment has been hidden.
This comment has been hidden.
Look at my comment way, way below.
This comment has been hidden.
I also added random tests.
Approved
It's "weird", not "wierd".
This comment has been hidden.
This comment has been hidden.
i think i've done
Maaaaaaaybe a few random tests would be nice? ;-)
Added
This comment has been hidden.
Do you think you could explain why this works? I found the same link and solved it with that but I can't find anywhere an explanantion.
This comment has been hidden.
This comment has been hidden.
need some help to prevent congratulations when tests are failed also any feedback are welcome
You need to manually do a equality checking yourself and maintain the
failed
flag.This comment has been hidden.