Ad
  • Custom User Avatar

    Only in rare cases will Array.Sort perform in O(n) time. More likely, it will be O(n log n) time.
    See here for more details: https://docs.microsoft.com/en-us/dotnet/api/system.array.sort?view=netframework-4.8

  • Custom User Avatar

    but you are not meeting the requirements

  • Custom User Avatar

    Done in O(n) time with comments! Very well done!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    myjinxin2015 is a javascript wizard I would do well to learn from

  • Custom User Avatar

    Hacker solution for sure! Makes no sense to this javascript noob & works and described. Well done!
    I'll be running this through a debugger to figure it out!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    @Voile
    IDK about JS terminology, but in C/C++ "expression" is something that has a value, so

    • the first part in for (...) isn't an expression;
    • var a=1,b=2,c=3 is a statement but not an expression; the only expressions here are 1, 2 and 3;
    • etc.
  • Custom User Avatar

    The opening part of a for loop in JS consists of 3 expressions (separated by ;), and each statement can have multiple run-off statements in a row (separated by , instead). Since var a=1,b=2,c=3 and such is a valid (multi-statement) expression it's a valid for loop. In fact it's valid in C and other languages too: int a,b,c; for(a=1,b=2,c=3;a<10;a++); is valid and works just as intended.

    Of course, putting too much stuff inside the for loop is not my style ;-) But I don't think it's that unreadable in the first place.

  • Custom User Avatar

    Im a newbie to javascript and this website. Not a total newb, though will not spout credentials. Im trying to understand the code and the culture here. I'm not trying to start a flame war, trying to engage with others

    Tried to be respectful in my questions and I have not.

    I am sorry that I have been passive aggressive with "You see beautiful, I see can't read". Did not realize that such discussions are passive-aggressive. Will not speak of such in the future. What I wanted was an explaination on a novel(to me) for loop with multiple variable initializations in the intial expression. I should not have stated my opinion on whether the code was golfed or not.

    Thank you for the clarification,(especially Avanta) all who have contributed to this discussion.

    As I understand now:

    i is the control var in the initial expression of the for loop. The initialExpression of the for loop can contan multiple variables in the scope of the loop.

  • Custom User Avatar

    If you keep mentioning "is this a newb thing" twice in one comment perhaps you should just admit that you're a newbie and you're probably not qualified to give strong opinions about this.

    (Yes, I'm talking about those "this is clever but not best practice" comments, they've since long become passive-aggressive assertions about "code that is short and does the task but I don't like it so I have to diss it".)

    Also, this is JS, not C or Java or anything. Their syntax look similar but they're very different.

  • Custom User Avatar

    This code reminds me of the book "If Hemingway Wrote JavaScript". Beautiful solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Of course one can initialize more than one variable per line. That is not my confusion.
    Is i is the loop control var?
    Are l and r part of the loop control logic?
    That is what is unclear about the code
    Am i correct in assuming that the code would work just the same if
    l and r were initialized out side the loop?
    Thank you for taking time to explain

  • Custom User Avatar

    you can initialise more than one variable on a line, eg:
    var a, b, c = 1, d = 5;

  • Loading more items...