Skip to content

Latest commit

 

History

History
112 lines (62 loc) · 3.28 KB

array.md

File metadata and controls

112 lines (62 loc) · 3.28 KB

Awesome JavaScript in one line of code written above a picture of Mt. Fuji's peak

Array

Exported as arr from `./array/index'

average

Returns the average of the sum of all items in a numerical array. Beware of JavaScript's Automatic Type Conversion if your Array contains something else than Numbers.

clean

Returns a new array without empty strings, NaN, null, undefined items.

cleanFalsy

  • Returns a new array without empty strings, NaN, null, undefined, false and 0 items.

closestNumber

Returns the numerical item closest to the given number.

`evenItems``

Returns a new array which contains every even item of the original array.

highestNumber

Returns the highest coerced numerical numerical item of the array.

`indexOfHighestNumber``

Returns the index of the first occurrence of the highest numerical item of the array.

`indexOfLowestNumber``

Returns the index of the first occurrence of the lowest numerical item of the array.

isEmpty

Returns a boolean false if the array is not empty or a boolean true if the array is empty.

longestString

Returns the longest string entry of the array.

lowestNumber

Returns the lowest numerical item of the array.

mergeArrayUnique

Returns a new Array which contains all the values of the two Arrays. Ensures that the new array contains only unique values.

mergeArray

Returns a new Array which contains all items of the two Arrays.

'nthItems`

Returns a new array which contains every n-th item of the original array.

`shuffle``

Returns a new array with shuffled items. Be aware, that the shuffled items are not truly random because Math.random will return a pseudo-random number.

sortAsc

Returns a new Array sorted by ascending order (Numbers). Beware of JavaScripts Automatic Type Conversion if your Array contains something else than Numbers.

sortDesc

Returns a new Array sorted by descending order (Numbers). Beware of JavaScripts Automatic Type Conversion if your Array contains something else than Numbers.

sum

Returns the sum of all items in a numerical array. Beware of JavaScript's Automatic Type Conversion if your Array contains something else than Numbers.

`oddItems``

Returns a new array which contains every odd (second) item of the original array.

occurrenceMap

Returns an object where the keys are the array entries and the values the number of their occurrences.

removeDuplicates

Returns a copy of the array. Removes duplicate entries, keep in mind that it works only for entries with primitive values (string, number, bigint, boolean, undefined, symbol, and null). Preserves the order of the entries.

shallowClone

Creates a shallow-copied clone of the provided array. Since it's a shallow copy, nested objects or arrays will be copied by reference, not duplicated.

shortestString

Returns the shortest string entry of the array.

shortestStringLength

Returns the length of the longest string entry of an Array of strings.

splitInHalf

Returns an new array where the first entry is the "first" and the second entry is the "second" half or the original array.

License

Licensed under the MIT license. MIT - http://www.opensource.org/licenses/mit-license.php