I will write more, I promise.
I've been doing some leetcode and practicing my typing. So I pretend to write more about these two subjects.
I'm also not generating these stuff with ChatGPT and pretend to write more of my thoughts instead just being some random subject IA generated.
BUT I'm guiding through other articles about one liners and I know that subject is really simple and have another articles that you can search here on dev.to
But that's it, I hope y'all like it and share with your friends.
Array
Remove false values from array
arr.filter(Boolean)
Remove duplicates from array
[...new Set(input)]
Swap between 2 elements
[a, b] = [b, a]
Remove holes from array
input.flat(0)
Casting to array of numbers
input.map(Numbers)
Clone an array
input.slice(0)
[...input]
Array.from(input)
Merge multiple arrays
(...input) => input.flat(1)
Objects
Checking if the object is empty
Object.keys(obj).length === 0;
Strings
Removing whitespaces in a string
str.replace(/\s/g, '');
Generating random string
Math.random().toString(36).slice(2);
Reverse a string
input.split('').reverse().join('')
Numbers
Generate random integer
Math.floor((Math.random() * (max - min + 1)) + min)
Top comments (0)