30 seconds of code

Beginner snippets

Click on a snippet card to view the snippet.

all

Returns true if the provided predicate function returns true for all elements in a collection, false otherwise.

allEqual

Check if all elements in an array are equal.

any

Returns true if the provided predicate function returns true for at least one element in a collection, false otherwise.

approximatelyEqual

Checks if two numbers are approximately equal to each other.

atob

Decodes a string of data which has been encoded using base-64 encoding.

average

Returns the average of two or more numbers.

btoa

Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data.

byteSize

Returns the length of a string in bytes.

castArray

Casts the provided value as an array if it's not one.

checkProp

Given a predicate function and a prop string, this curried function will then take an object to inspect by calling the property and passing it to the predicate.

clampNumber

Clamps num within the inclusive range specified by the boundary values a and b.

coalesce

Returns the first non-null/undefined argument.

compact

Removes falsy values from an array.

compactWhitespace

Returns a string with whitespaces compacted.

createDirIfNotExists

Creates a directory, if it does not exist.

createElement

Creates an element from a string (without appending it to the document). If the given string contains multiple elements, only the first one will be returned.

currentURL

Returns the current URL.

dayOfYear

Gets the day of the year from a Date object.

degreesToRads

Converts an angle from degrees to radians.

difference

Returns the difference between two arrays.

digitize

Converts a number to an array of digits.

distance

Returns the distance between two points.

drop

Returns a new array with n elements removed from the left.

dropRight

Returns a new array with n elements removed from the right.

everyNth

Returns every nth element in an array.

factorial

Calculates the factorial of a number.

fibonacci

Generates an array, containing the Fibonacci sequence, up until the nth term.

filterFalsy

Filters out the falsy values in an array.

filterNonUnique

Filters out the non-unique values in an array.

findLast

Returns the last element for which the provided function returns a truthy value.

functionName

Logs the name of a function.

gcd

Calculates the greatest common divisor between two or more numbers/arrays.

getImages

Fetches all images from within an element and puts them into an array

getMeridiemSuffixOfInteger

Converts an integer to a suffixed string, adding am or pm based on its value.

getStyle

Returns the value of a CSS rule for the specified element.

getType

Returns the native type of a value.

hammingDistance

Calculates the Hamming distance between two values.

hasClass

Returns true if the element has the specified class, false otherwise.

head

Returns the head of a list.

hide

Hides all the elements specified.

inRange

Checks if the given number falls within the given range.

indentString

Indents each line in the provided string.

initial

Returns all the elements of an array except the last one.

insertAfter

Inserts an HTML string after the end of the specified element.

insertBefore

Inserts an HTML string before the start of the specified element.

is

Checks if the provided value is of the specified type.

isAfterDate

Check if a date is after another date.

isBeforeDate

Check if a date is before another date.

isBoolean

Checks if the given argument is a native boolean element.

isBrowserTabFocused

Returns true if the browser tab of the page is focused, false otherwise.

isDivisible

Checks if the first numeric argument is divisible by the second one.

isEmpty

Returns true if the a value is an empty object, collection, has no enumerable properties or is any type that is not considered a collection.

isEven

Returns true if the given number is even, false otherwise.

isFunction

Checks if the given argument is a function.

isLowerCase

Checks if a string is lower case.

isNegativeZero

Checks if the given value is equal to negative zero (-0).

isNil

Returns true if the specified value is null or undefined, false otherwise.

isNull

Returns true if the specified value is null, false otherwise.

isNumber

Checks if the given argument is a number.

isObject

Returns a boolean determining if the passed value is an object or not.

isObjectLike

Checks if a value is object-like.

isPrime

Checks if the provided integer is a prime number.

isSameDate

Check if a date is the same as another date.

isString

Checks if the given argument is a string. Only works for string primitives.

isSymbol

Checks if the given argument is a symbol.

isUndefined

Returns true if the specified value is undefined, false otherwise.

isUpperCase

Checks if a string is upper case.

isWeekday

Results in a boolean representation of a specific date.

isWeekend

Results in a boolean representation of a specific date.

last

Returns the last element in an array.

lcm

Returns the least common multiple of two or more numbers.

mapNumRange

Maps a number from one range to another range.

mapString

Creates a new string with the results of calling a provided function on every character in the calling string.

maxBy

Returns the maximum value of an array, after mapping each element to a value using the provided function.

maxDate

Returns the maximum of the given dates.

maxN

Returns the n maximum elements from the provided array. If n is greater than or equal to the provided array's length, then return the original array (sorted in descending order).

midpoint

Calculates the midpoint between two pairs of (x,y) points.

minBy

Returns the minimum value of an array, after mapping each element to a value using the provided function.

minDate

Returns the minimum of the given dates.

minN

Returns the n minimum elements from the provided array. If n is greater than or equal to the provided array's length, then return the original array (sorted in ascending order).

negate

Negates a predicate function.

nodeListToArray

Converts a NodeList to an array.

none

Returns true if the provided predicate function returns false for all elements in a collection, false otherwise.

nthArg

Creates a function that gets the argument at index n. If n is negative, the nth argument from the end is returned.

nthElement

Returns the nth element of an array.

objectFromPairs

Creates an object from the given key-value pairs.

objectToPairs

Creates an array of key-value pair arrays from an object.

offset

Moves the specified amount of elements to the end of the array.

pad

Pads a string on both sides with the specified character, if it's shorter than the specified length.

powerset

Returns the powerset of a given array of numbers.

radsToDegrees

Converts an angle from radians to degrees.

randomHexColorCode

Generates a random hexadecimal color code.

randomIntegerInRange

Returns a random integer in the specified range.

randomNumberInRange

Returns a random number in the specified range.

readFileLines

Returns an array of lines from the specified file.

redirect

Redirects to a specified URL.

reject

Filters an array's values based on a predicate function, returning only values for which the predicate function returns true.

reverseString

Reverses a string.

sample

Returns a random element from an array.

setStyle

Sets the value of a CSS rule for the specified element.

shallowClone

Creates a shallow clone of an object.

show

Shows all the elements specified.

similarity

Returns an array of elements that appear in both arrays.

sortCharactersInString

Alphabetically sorts the characters in a string.

splitLines

Splits a multiline string into an array of lines.

stripHTMLTags

Removes HTML/XML tags from string.

sum

Returns the sum of two or more numbers/arrays.

tail

Returns all elements in an array except for the first one.

take

Returns an array with n elements removed from the beginning.

timeTaken

Measures the time taken by a function to execute.

toDecimalMark

toSafeInteger

Converts a value to a safe integer.

toggleClass

Toggle a class for an element.

truncateString

Truncates a string up to a specified length.

unescapeHTML

Unescapes escaped HTML characters.

union

Returns every element that exists in any of the two arrays once.

uniqueElements

Returns all unique values of an array.

untildify

Converts a tilde path to an absolute path.

vectorDistance

Returns the distance between two vectors.

without

Filters out the elements of an array, that have one of the specified values.