I'm interested in your favorite code snippet. It can be in any language.
Please share it in the comments below.
Mine is a way to swap to variables without using a temporary variable:
var a = 5;
var b = 3;
var a = b + a;
var b = a - b;
var a = a - b;
After that a is equal to 3 and b is equal to 5. We have swapped the variables without using a third variable.
Alternate way of swapping two vars without using a third:
I'm also a fan of Java 8 streams:
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Cool XOR swap. Didn't know this trick! Really neat.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
var port = process.env.PORT || 8000
It's just so fancy using the pipes to set a default value when the initial value is undefined.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Good example! Ty
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit