Ad
  • Custom User Avatar

    ...for anyone who don't know JS.

  • Custom User Avatar

    think that's the point

  • Default User Avatar

    it's what the cool kids to. Makes them look smart and dumb at the same time

  • Default User Avatar

    In the context of a function that can be expressed as a very short chain of basic methods, I think this syntax is fine and readable.

    Obviously you wouldn't cram an extensive and complex function into this kind of one-line solution, but all THIS function needs to do is apply a few methods to a single argument and return it. Perfect use-case for shorthands if there ever was one. If we're worried about who else has to read and work with the code, giving each method its own line would resolve that well enough.

  • Custom User Avatar

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

  • Custom User Avatar

    Semantic reasons, splits into named variables for readability

    This depends on the reason you're writing code. It's your job/homework, and other people will have to work with your code or review it? Of course, it's a good idea to split stuff into variables (better readability). But there's no reason why you absolutely must use self-explaining constructs (like Number() instead of +, or String() instead of +"") because you can still explain everything with comments.

    On the other hand, if all you do is complete a small task on a competitive programming website, there's no reason to stretch everything into as many lines as possible and write "100% understandable code"; on the contrary, you're doing lots of useless work because "newbies may not understand some interesting language features because they've never encountered any code using those because everybody writes in the same dull pre-ES6 manner".

  • Custom User Avatar

    > Writes a 1-line solution but splits it into 5 lines because reasons
    > Talks about how 1-line solutions are evil

    How is your code any better?

  • Custom User Avatar

    Wow, what a complete noob with a completely closed attitude up there!

  • Custom User Avatar

    I would disagree :) PS. unary plus before a is redundant though.

  • Custom User Avatar

    I had difficulty to parse that length invokes after filtering is completed at first glance :)

  • Custom User Avatar

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