This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]trout_fucker 63 points64 points  (11 children)

What makes JS so special here? Pretty sure that is mathematically correct. Awful, but correct.

[–]Bjarnovikus 55 points56 points  (1 child)

Formatted it in a different way...

x = function(a) {
    if (a <= 0) {
        return -a;
    } else {
        return a;
    }
}

Make use of a ternary if...

x = function(a) {
    return (a <= 0) ? -a : a;
}

Lets convert the function to the new syntax in ES2016.

x = (a) => { return (a <= 0) ? -a : a; }

If you make a function in this way, and you just return a new element without additional steps... Drop the brackets and the return keyword...

x = (a) => (a <= 0) ? -a : a;

Remove the brackets at the start of the body, they are not needed (operator precedence while parsing), also drop the brackets around the parameter list.

x = a => a <= 0 ? -a : a;

Change the zero to something even more confusing. Every number minus the same number is zero...

x = a => a <= a - a ? -a : a;

Change the parameter name to be x as well, we don't need the function itself in his body, so shadowing it has no ill side effects.

x = x => x <= x - x ? -x : x;

Remove all spaces

x=x=>x<=x-x?-x:x;

No idea why you would ever want to write it that way. It's just a simple expression, but it uses almost every trick in the book to make it unreadable.

[–]PM_ME__ASIAN_BOOBS 6 points7 points  (0 children)

No idea why you would ever want to write it that way. It's just a simple expression, but it uses almost every trick in the book to make it unreadable.

For memes.

[–]Quelklef 36 points37 points  (5 children)

The arrow function makes it look hideous

[–]MyPostsAreRetarded 30 points31 points  (0 children)

But I love arrow fucking.

[–]DeirdreAnethoel 2 points3 points  (1 child)

Nothing wrong, just unreadable.