9 Tweets Mar 15, 2023
Want to polish your JavaScript skills? Here are 7 killer one-liners in JavaScript which will drastically help you improve 🀯
1. Shuffle Array
While using algorithms that require some degree of randomization, you will often find shuffling arrays quite a necessary skill. The following snippet shuffles an array in place with O(n log n) complexity.
2. Copy to Clipboard
In web apps, copy to clipboard is rising in popularity due to its convenience.
P.S. - The approach works for 93.08% users. So the check is necessary that the user’s browser supports the API. To support all users, you can use an input & copy its contents.
3. Unique Elements
Every language has its own implementation of Hash List, in JavaScript, it is called Set. You can easily get the unique elements from an array using the Set Data Structure.
4. Detect Dark Mode
With the rising popularity of dark mode, it is ideal to switch your app to dark mode if the user has it enabled in their device. Luckily, "media queries" can be utilized for making the task a walk in the park.
5. Scroll To Top
Beginners very often find themselves struggling with scrolling elements into view properly. The easiest way to scroll elements is to use the "scrollIntoView" method. Add behavior: "smooth" for a smooth scrolling animation.
6. Scroll To Bottom
Just like the "scrollToTop" method, the "scrollToBottom" method can easily be implemented using the "scrollIntoView" method, only by switching the block value to end.
7. Generate Random Color
Does your application rely on random color generation? The following snippet absolutely got you covered!
That's a wrap!
If you enjoyed this thread:
1. Follow @codedamncom for more of these
2. RT the tweet below to share this thread with your audience

Loading suggestions...