If this sounds compelling to you, here’s a list of 127 beneficial snippets taken from this project that you can learn and use immediately.
This snippet returns
true if the predicate function returns
true for all elements in a collection and
false otherwise. You can omit the second argument
fn if you want to use
Boolean as a default value.
This snippet checks whether all elements of the array are equal.
This snippet checks whether two numbers are approximately equal to each other, with a small difference.
This snippet converts the elements that don’t have commas or double quotes to strings with comma-separated values.
This snippet converts the elements of an array into
<li> tags and appends them to the list of the given ID.
This snippet executes a function, returning either the result or the caught error object.
This snippet returns the average of two or more numerical values.
This snippet returns the average of an array after initially doing the mapping of each element to a value using a given function.
This snippet splits values into two groups and then puts a truthy element of
filter in the first group, and in the second group otherwise.
You can use
Array.prototype.push() to add elements to groups based on
This snippet splits values into two groups, based on a predicate function. If the predicate function returns a truthy value, the element will be placed in the first group. Otherwise, it will be placed in the second group.
You can use
Array.prototype.push() to add elements to groups, based on the value returned by
fn for each element.
This snippet checks whether the bottom of a page is visible.
This snippet returns the length of a string in bytes.
This snippet capitalizes the first letter of a string.
This snippet capitalizes the first letter of every word in a given string.
This snippet converts a non-array value into array.
This snippet removes false values from an array.
This snippet counts the occurrences of a value in an array.
18. Create Directory
This snippet uses
existsSync() to check whether a directory exists and then
mkdirSync() to create it if it doesn’t.
This snippet returns the current URL.
This snippet gets the day of the year from a