Ad
  • Custom User Avatar

    You need to achieve O(log(n))

  • Custom User Avatar

    For "expected null but was 163" the input was not the one you give. It is a "Sample Tests:" so you can read it.

  • Custom User Avatar
  • Custom User Avatar

    .

  • Custom User Avatar

    ['2', 101].sort() resulted in ['2', 101] here

    You sure about that? Doesn't sound right to me, and this doesn't support your claim:

    function orderWeight(strng) {
        console.log(['2', 101].sort())
    }
    
    Log
    [ 101, '2' ]
    

    from mdn (which I linked to above):

    If compareFunction is not supplied, all non-undefined array elements are sorted by converting them to strings and comparing strings in UTF-16 code units order.

    which means 101 should come first, and it seems to do so here. it would be surprising if it didn't. and it is insane (actually it's not so crazy for mixed types, but you'd get the same result for [2, 101]).

    My guess is that you are sorting twice and that the non-stable sort is what gets you?

  • Custom User Avatar

    You might be relying on Array.prototype.sort to be stable but that isn't necessarily true for slightly older versions.

  • Custom User Avatar

    but when I run the same program on repl.it or locally everything works

    that's only meaningful if you're running the exact same tests. people keep saying something to that effect and it turns out they did something else and that the difference wasn't from the change of environment

    not sure what exactly you're asking. make sure that whatever you're relying on is defined behaviour I guess? and javascript is really really uh.. special, when it comes to comparing things

    > [7, 8, 9, 10].sort()
    [ 10, 7, 8, 9 ]
    

    such a great language :')

  • Custom User Avatar

    I guess you run out of digits. Floating point breaks pretty soon with factorial

  • Custom User Avatar

    It's not the author who gives the kyu. Good you enjoyed it!