These are our favorite one-liners that we've used and forgot existed because they work so well 😁.
Generate a random hex color
const ...
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
Math.floor(Math.random() * 0xffffff)
gives numbers in the range0..0xfffffe
, not0..0xffffff
. You wantMath.floor(Math.random() * (0xffffff + 1))
, i.e.Math.floor(Math.random() * 0x1000000)
😉this guy hexes...
Reverse string can be shortened to:
Your version also has an issue with unicode, which the above function fixes:
Filtering falsy values can also be shortened:
niiiiiice
Cool really helped me!
sweet! thanks for the feedback!
🔥
JavaScript's magic
Filtering falsy values can also be done like...
const removeFalsyValues = arr => arr.filter(Boolean)
Thanks for your good article!
we actually had it this way originally 😄. both ways work, i think the updated one may save a character or two. i'll add a note, so that both are covered though!
Really cool
Thanks!