Retired

-Reverse it, quickly! (retired)

3,444 of 3,446avadakedavra
Description
Loading description...
Arrays
Puzzles
Restricted
  • Please sign in or sign up to leave a comment.
  • rese2112 Avatar

    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.

  • jpssj Avatar

    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 to n-1, then the second element as the maximum of the subarray with indices from 1 to n-1, and so on up to n-1 ? Could someone please explain/confirm it ?

  • DohertyC12 Avatar

    This is what I've tried, still to long: weirdReverse=a=>a.map(a.pop,[... a])

  • Lucasss Avatar

    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.

  • farhanaditya Avatar

    This kata isn't compatible with newer Node versions as it relies on a specific behavior of .sort in Node v8.

  • pavel.verhovod Avatar

    The algorithms have already changed. 13 characters would be relevant;

  • renku Avatar

    This is the worst kata I've experienced. You either know the expected solution or you don't. Nothing to learn from this.

  • hash_is_hashed Avatar

    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 ?

  • Quaternions Avatar

    "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!... >:("

  • Anurag RW Avatar

    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.

  • Eva-Rosalene Avatar

    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.

  • rudimadima Avatar

    "Solution" doesn't works in my Chrome.

  • jg0x42 Avatar

    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]

    compareFunction(a, b) must always return the same value when given a specific pair of elements a and b as its two arguments. If inconsistent results are returned, then the sort order is undefined.

    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.

  • KSahithyan Avatar

    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.

  • hooked74 Avatar

    The solution only works up to version 11 of the node

  • akivalevy Avatar

    The solutions provided are flawed and incorrect by way of the described requirements of the array containing data of any type:

    weirdReverse([1,2,3,4,[],null,Infinity,-Infinity,NaN,{},()=>{},undefined])
    

    yields proof:

    [ null,
      [Function],
      1,
      {},
      NaN,
      -Infinity,
      Infinity,
      2,
      [],
      4,
      3,
      undefined 
    ]
    

    In other words, this challenge is impossible to solve at the current character limit.

  • StupendouS Avatar

    lol how do these solutions work? they dont do anything in console, only if you return -1 instead of 1, then it works

  • nsticco Avatar

    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.

  • user8436785 Avatar

    4 kyu? It's so easy. Seems liek 8 kyu practically

  • user8436785 Avatar

    Seriously, 4 kyu? It is so easy.

  • Arjunalapsapkota Avatar

    This comment has been hidden.

  • er-parag91 Avatar

    This comment has been hidden.

  • TeoDiaz Avatar

    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. :)

  • Frankoloko Avatar

    This comment has been hidden.

  • b96613012 Avatar

    Can't love this kata anymore!!!

  • dke Avatar

    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

  • KKOKU Avatar

    This comment has been hidden.

  • Manish-Giri Avatar

    This comment has been hidden.

  • tvolf Avatar

    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.

  • Unnamed Avatar

    My next shortest is 35 chars and it should work for any input. Is 35 small enough for another kata?

  • smolen Avatar

    This comment has been hidden.

  • docgunthrop Avatar

    This comment has been hidden.

  • Voile Avatar

    I also added random tests.

  • Voile Avatar

    Approved

  • Unnamed Avatar

    It's "weird", not "wierd".

  • Voile Avatar

    This comment has been hidden.

  • Voile Avatar

    Maaaaaaaybe a few random tests would be nice? ;-)

  • Voile Avatar

    This comment has been hidden.

  • avadakedavra Avatar

    need some help to prevent congratulations when tests are failed also any feedback are welcome