# 30 seconds of code

## Array

Click on a snippet card to view the snippet.

#### JSONtoCSV

Converts an array of objects to a comma-separated values (CSV) string that contains only the `columns`

specified.

#### 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.

#### arrayToCSV

Converts a 2D array to a comma-separated values (CSV) string.

#### bifurcate

Splits values into two groups. If an element in `filter`

is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.

#### bifurcateBy

Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group.

#### chunk

Chunks an array into smaller arrays of a specified size.

#### compact

Removes falsy values from an array.

#### countBy

Groups the elements of an array based on the given function and returns the count of elements in each group.

#### countOccurrences

Counts the occurrences of a value in an array.

#### deepFlatten

Deep flattens an array.

#### difference

Returns the difference between two arrays.

#### differenceBy

Returns the difference between two arrays, after applying the provided function to each array element of both.

#### differenceWith

Filters out all values from an array for which the comparator function does not return `true`

.

#### drop

Returns a new array with `n`

elements removed from the left.

#### dropRight

Returns a new array with `n`

elements removed from the right.

#### dropRightWhile

Removes elements from the end of an array until the passed function returns `true`

. Returns the remaining elements in the array.

#### dropWhile

Removes elements in an array until the passed function returns `true`

. Returns the remaining elements in the array.

#### everyNth

Returns every nth element in an array.

#### filterFalsy

Filters out the falsy values in an array.

#### filterNonUnique

Filters out the non-unique values in an array.

#### filterNonUniqueBy

Filters out the non-unique values in an array, based on a provided comparator function.

#### findLast

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

#### findLastIndex

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

#### flatten

Flattens an array up to the specified depth.

#### forEachRight

Executes a provided function once for each array element, starting from the array's last element.

#### groupBy

Groups the elements of an array based on the given function.

#### head

Returns the head of a list.

#### indexOfAll

Returns all indices of `val`

in an array.
If `val`

never occurs, returns `[]`

.

#### initial

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

#### initialize2DArray

Initializes a 2D array of given width and height and value.

#### initializeArrayWithRange

Initializes an array containing the numbers in the specified range where `start`

and `end`

are inclusive with their common difference `step`

.

#### initializeArrayWithRangeRight

Initializes an array containing the numbers in the specified range (in reverse) where `start`

and `end`

are inclusive with their common difference `step`

.

#### initializeArrayWithValues

Initializes and fills an array with the specified values.

#### initializeNDArray

Create a n-dimensional array with given value.

#### intersection

Returns a list of elements that exist in both arrays.

#### intersectionBy

Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both.

#### intersectionWith

Returns a list of elements that exist in both arrays, using a provided comparator function.

#### isSorted

Returns `1`

if the array is sorted in ascending order, `-1`

if it is sorted in descending order or `0`

if it is not sorted.

#### join

Joins all elements of an array into a string and returns this string. Uses a separator and an end separator.

#### last

Returns the last element in an array.

#### longestItem

Takes any number of iterable objects or objects with a `length`

property and returns the longest one.
If multiple objects have the same length, the first one will be returned.
Returns `undefined`

if no arguments are provided.

#### mapObject

Maps the values of an array to an object using a function, where the key-value pairs consist of the stringified value as the key and the mapped value.

#### 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).

#### 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).

#### none

Returns `true`

if the provided predicate function returns `false`

for all elements in a collection, `false`

otherwise.

#### nthElement

Returns the nth element of an array.

#### offset

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

#### partition

Groups the elements into two arrays, depending on the provided function's truthiness for each element.

#### permutations

⚠️ **WARNING**: This function's execution time increases exponentially with each array element. Anything more than 8 to 10 entries will cause your browser to hang as it tries to solve all the different combinations.

Generates all permutations of an array's elements (contains duplicates).

#### pull

Mutates the original array to filter out the values specified.

#### pullAtIndex

Mutates the original array to filter out the values at the specified indexes.

#### pullAtValue

Mutates the original array to filter out the values specified. Returns the removed elements.

#### pullBy

Mutates the original array to filter out the values specified, based on a given iterator function.

#### reduceSuccessive

Applies a function against an accumulator and each element in the array (from left to right), returning an array of successively reduced values.

#### reduceWhich

Returns the minimum/maximum value of an array, after applying the provided function to set comparing rule.

#### reducedFilter

Filter an array of objects based on a condition while also filtering out unspecified keys.

#### reject

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

.

#### remove

Removes elements from an array for which the given function returns `false`

.

#### sample

Returns a random element from an array.

#### sampleSize

Gets `n`

random elements at unique keys from `array`

up to the size of `array`

.

#### shank

Has the same functionality as `Array.prototype.splice()`

, but returning a new array instead of mutating the original array.

#### shuffle

Randomizes the order of the values of an array, returning a new array.

#### similarity

Returns an array of elements that appear in both arrays.

#### sortedIndex

Returns the lowest index at which value should be inserted into array in order to maintain its sort order.

#### sortedIndexBy

Returns the lowest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function.

#### sortedLastIndex

Returns the highest index at which value should be inserted into array in order to maintain its sort order.

#### sortedLastIndexBy

Returns the highest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function.

#### stableSort

Performs stable sorting of an array, preserving the initial indexes of items when their values are the same. Does not mutate the original array, but returns a new array instead.

#### symmetricDifference

Returns the symmetric difference between two arrays, without filtering out duplicate values.

#### symmetricDifferenceBy

Returns the symmetric difference between two arrays, after applying the provided function to each array element of both.

#### symmetricDifferenceWith

Returns the symmetric difference between two arrays, using a provided function as a comparator.

#### tail

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

#### take

Returns an array with n elements removed from the beginning.

#### takeRight

Returns an array with n elements removed from the end.

#### takeRightWhile

Removes elements from the end of an array until the passed function returns `true`

. Returns the removed elements.

#### takeWhile

Removes elements in an array until the passed function returns `true`

. Returns the removed elements.

#### toHash

Reduces a given Array-like into a value hash (keyed data store).

#### union

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

#### unionBy

Returns every element that exists in any of the two arrays once, after applying the provided function to each array element of both.

#### unionWith

Returns every element that exists in any of the two arrays once, using a provided comparator function.

#### uniqueElements

Returns all unique values of an array.

#### uniqueElementsBy

Returns all unique values of an array, based on a provided comparator function.

#### uniqueElementsByRight

Returns all unique values of an array, based on a provided comparator function, starting from the right.

#### uniqueSymmetricDifference

Returns the unique symmetric difference between two arrays, not containing duplicate values from either array.

#### unzipWith

Creates an array of elements, ungrouping the elements in an array produced by zip and applying the provided function.

#### without

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

#### xProd

Creates a new array out of the two supplied by creating each possible pair from the arrays.

#### zip

Creates an array of elements, grouped based on the position in the original arrays.

#### zipObject

Given an array of valid property identifiers and an array of values, return an object associating the properties to the values.

#### zipWith

Creates an array of elements, grouped based on the position in the original arrays and using function as the last value to specify how grouped values should be combined.