Options
All
  • Public
  • Public/Protected
  • All
Menu

Module array

Array Functions

arraySortStrings

  • arraySortStrings(array: string[]): string[]
  • name

    arraySortStrings

    description

    Sort an array of strings. Creates a new array.

    summary

    import { arraySortStrings } from '@corefunc/corefunc/array/sort/strings';

    Parameters

    • array: string[]

      Array of strings.

    Returns string[]

    Sorted array of strings.

Array Basic Functions

arrayBasicExtend

  • arrayBasicExtend<AlphaTypes, BetaTypes, ResultingTypes>(alpha?: AlphaTypes[] | ReadonlyArray<AlphaTypes>, beta?: BetaTypes[] | ReadonlyArray<BetaTypes>, shouldBeUnique?: boolean): ResultingTypes[]
  • name

    arrayBasicExtend

    description

    Extend one array with another.

    Type parameters

    • AlphaTypes: unknown

    • BetaTypes: unknown

    • ResultingTypes: unknown

    Parameters

    • alpha: AlphaTypes[] | ReadonlyArray<AlphaTypes> = []
    • beta: BetaTypes[] | ReadonlyArray<BetaTypes> = []
    • shouldBeUnique: boolean = false

    Returns ResultingTypes[]

    Resulting array.

arrayBasicPull

  • arrayBasicPull<T>(array: T[], value: any): T[]
  • name

    arrayBasicPull

    description

    Remove all occurrences of value from array. Creates new array.

    summary

    import { arrayBasicPull } from '@corefunc/corefunc/array/basic/pull';

    example

    arrayBasicPull([1, 2, 3, 4, 5, 3, 6, 7, 3, 9], 3); // [1, 2, 4, 5, 6, 7, 9]

    Type parameters

    • T

    Parameters

    • array: T[]

      Array of any values.

    • value: any

      Value to remove from array.

    Returns T[]

    New array without value.

arrayBasicShuffle

  • arrayBasicShuffle<T>(array: T[]): T[]
  • name

    arrayBasicShuffle

    description

    Shuffles array. Modified by reference.

    summary

    import { arrayBasicShuffle } from "@corefunc/corefunc/array/basic/shuffle";

    since

    0.3.27

    example

    arrayBasicShuffle([2, 11, 37, 42])

    Type parameters

    • T

    Parameters

    • array: T[]

      Array to be shuffled.

    Returns T[]

    Modified array.

arrayBasicWith

  • arrayBasicWith<T>(array: T[], index: number, value: unknown, suppressErrors?: boolean): T[]
  • name

    arrayBasicWith

    description

    Change the value of a given index. It returns a new array.

    summary

    import { arrayBasicWith } from '@corefunc/corefunc/array/basic/with';

    throws

    {RangeError} Incorrect index.

    since

    0.3.62

    example
    const array = [1, 2, 3];
    const index = 2;
    if (index in array) {
      const copy = arrayBasicWith(array, index, 300);
      console.log(array); // [1, 2, 3]
      console.log(copy); // [1, 2, 300]
    }
    

    Type parameters

    • T

    Parameters

    • array: T[]

      The array to copy and change.

    • index: number

      The index of the element to change.

    • value: unknown

      The value to set.

    • suppressErrors: boolean = true

    Returns T[]

    A new array with the element at index replaced with value.

arrayGetRandom

  • arrayGetRandom<T>(array: T[]): T
  • name

    arrayGetRandom

    description

    Get random value from array.

    summary

    import { arrayGetRandom } from "@corefunc/corefunc/array/get/random";

    since

    0.3.27

    example

    arrayGetRandom([2, 11, 37, 42]); āžœ 42

    Type parameters

    • T

    Parameters

    • array: T[]

      Array pick from.

    Returns T

    Array item.

Array Flat Functions

arrayFlatUnique

  • arrayFlatUnique(arrayMergeInto: any, ...arraysToBeAdded: any[]): any[]
  • name

    arrayFlatUnique

    description

    Merge arrays. Makes flat. Makes unique.

    summary

    import { arrayFlatUnique } from '@corefunc/corefunc/array/flat/unique';

    since

    0.2.3

    Parameters

    • arrayMergeInto: any
    • Rest ...arraysToBeAdded: any[]

    Returns any[]

Array Is Functions

arrayIsList

  • arrayIsList(arraySupposedToBeList: unknown[]): boolean
  • name

    arrayIsList

    description
    Checks whether a given array is a list.
    An array is considered a list if its keys consist of consecutive numbers from `0` to `array.length-1`.
    This function works only on non-typed arrays.
    This function returns `true` on empty arrays.
    
    summary
    import { arrayIsList } from "@corefunc/corefunc/array/is/list";
    
    since

    0.3.17

    example
    console.log(arrayIsList([])); // āžœ true
    
    example
    console.log(arrayIsList(["šŸŒ", "šŸ", "šŸ‡", "šŸŠ"])); // āžœ true
    
    example
    console.log(arrayIsList(new Int16Array())); // āžœ false
    
    example
    const list = ["šŸŒ", "šŸ", "šŸ‡", "šŸŠ"];
    list[-1] = "šŸ“";
    console.log(list); // [ 'šŸŒ', 'šŸ', 'šŸ‡', 'šŸŠ', '-1': 'šŸ“' ]
    console.log(list.length); // 4
    console.log(Object.keys(list)); // [ '0', '1', '2', '3', '-1' ]
    console.log(arrayIsList(list)); // false
    

    Parameters

    • arraySupposedToBeList: unknown[]

      The array being evaluated.

    Returns boolean

    • Returns true if array is a list, false otherwise.

arrayIsSparse

  • arrayIsSparse(array: any[]): boolean
  • name

    arrayIsSparse

    description

    Check is array sparse.

    since

    0.3.5

    Parameters

    • array: any[]

    Returns boolean

Array Sort Functions

arraySortNumbers

  • arraySortNumbers(array: number[]): number[]
  • name

    arraySortNumbers

    description

    Sort an array of numbers. Creates a new array.

    summary

    import { arraySortNumbers } from '@corefunc/corefunc/array/sort/numbers';

    Parameters

    • array: number[]

      Array of numbers.

    Returns number[]

    Sorted array of numbers.

Array To Functions

arrayToReversed

  • arrayToReversed<T>(array: T[]): T[]
  • name

    arrayToReversed

    description

    Returns a new array with the elements in reversed order.

    summary

    import { arrayToReversed } from '@corefunc/corefunc/array/to/reversed';

    since

    0.3.62

    Type parameters

    • T

    Parameters

    • array: T[]

      Array to reverse.

    Returns T[]

    Reversed array.

arrayToSorted

  • arrayToSorted<T>(array: T[], compareFn?: function): T[]
  • name

    arrayToSorted

    description

    Sorts an array. Returns a new array.

    summary

    import { arrayToSorted } from '@corefunc/corefunc/array/to/sorted';

    since

    0.3.62

    Type parameters

    • T

    Parameters

    • array: T[]

      Array to sort.

    • Optional compareFn: function
        • (a: T, b: T): number
        • Parameters

          • a: T
          • b: T

          Returns number

    Returns T[]

    Sorted array.

arrayToSpliced

  • arrayToSpliced<T>(array: T[], start: number, deleteCount: number, ...items: T[]): T[]
  • name

    arrayToSpliced

    description

    Array to spliced. Returns a new array with the element at the specified index replaced by the given value.

    summary

    import { arrayToSpliced } from '@corefunc/corefunc/array/to/spliced';

    since

    0.3.62

    Type parameters

    • T

    Parameters

    • array: T[]

      Array to spliced.

    • start: number

      Index at which to start changing the array.

    • deleteCount: number

      An integer indicating the number of old array elements to remove.

    • Rest ...items: T[]

      The elements to add to the array, beginning at the start index.

    Returns T[]

    Returns a new array with the element at the specified index replaced by the given value.

Other Functions

arrayBasicAssign

  • arrayBasicAssign(assignTo: any[], assignFrom: any[]): any
  • Parameters

    • assignTo: any[]
    • assignFrom: any[]

    Returns any

arrayBasicHas

  • arrayBasicHas(array: any[], value: any, fromIndex?: number): boolean
  • Parameters

    • array: any[]
    • value: any
    • fromIndex: number = 0

    Returns boolean

arrayBasicHasSame

  • arrayBasicHasSame(alpha: any[], beta: any[]): boolean
  • name

    arrayBasicHasSame

    since

    0.1.13

    Parameters

    • alpha: any[]
    • beta: any[]

    Returns boolean

arrayBasicInsert

  • arrayBasicInsert(array: any[], index: number, item: any): any[]
  • Parameters

    • array: any[]
    • index: number
    • item: any

    Returns any[]

arrayBasicIntersect

  • arrayBasicIntersect(alpha: any[], beta: any[]): any[]
  • name

    arrayBasicIntersect

    Parameters

    • alpha: any[]
    • beta: any[]

    Returns any[]

arrayBasicKeep

  • arrayBasicKeep<T>(array: T[], iteratee: function): T[]
  • name

    arrayBasicKeep

    description

    Returns the elements of an array that meet the condition specified in a callback function.

    see

    https://twitter.com/rauschma/status/1253457185092308993

    Type parameters

    • T: unknown

    Parameters

    • array: T[]

      The array arrayBasicKeep was called upon.

    • iteratee: function

      A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.

        • (_value: T, _index: number, _array: T[]): boolean
        • Parameters

          • _value: T
          • _index: number
          • _array: T[]

          Returns boolean

    Returns T[]

    Returns the new filtered array.

arrayBasicMap

  • arrayBasicMap(array: any[], iteratee: function): any[]
  • description

    A specialized version of map for arrays without support for iteratee shorthands.

    Parameters

    • array: any[]
    • iteratee: function

      The function invoked per iteration.

        • (value?: any, index?: number, original?: any[]): object
        • Parameters

          • Optional value: any
          • Optional index: number
          • Optional original: any[]

          Returns object

    Returns any[]

    Returns the new mapped array.

arrayBasicMerge

  • arrayBasicMerge<T1, T2>(arrayMergeInto: T1[], arrayToBeAdded: T2[]): (T1 | T2)[]
  • name

    arrayBasicMerge

    description

    Merge one array into another. Modifies the first array, but less memory consuming.

    since

    0.1.13

    Type parameters

    • T1

    • T2

    Parameters

    • arrayMergeInto: T1[]

      The array to which will be added

    • arrayToBeAdded: T2[]

      The array to be added

    Returns (T1 | T2)[]

arrayBasicSize

  • arrayBasicSize(array: any[]): number
  • Parameters

    • array: any[]

    Returns number

arrayGetAt

  • arrayGetAt<T, E>(array: T[], index: number, onFail?: E): T | E
  • name

    arrayGetAt

    description

    Get the value at the index of an array. Supports negative index.

    example

    arrayGetAt(["šŸŒ", "šŸ", "šŸ‡", "šŸŠ"], -2) āžœ "šŸ‡"

    since

    0.0.96

    Type parameters

    • T

    • E

    Parameters

    • array: T[]
    • index: number
    • Optional onFail: E

    Returns T | E

arrayGetAverage

  • arrayGetAverage(array: number[]): number
  • name

    arrayGetAverage

    Parameters

    • array: number[]

    Returns number

arrayGetDifference

  • arrayGetDifference(alpha: any[], beta: any[]): any[]
  • Parameters

    • alpha: any[]
    • beta: any[]

    Returns any[]

arrayGetHead

  • arrayGetHead<T, E>(array: T[], onFail?: E): T | E
  • name

    arrayGetHead

    example

    arrayGetHead([,,"šŸŒ","šŸ","šŸŠ"]) āžœ "šŸŒ"

    Type parameters

    • T

      Type of array

    • E

      Type of default value

    Parameters

    • array: T[]
    • Optional onFail: E

    Returns T | E

arrayGetSymmetricDifference

  • arrayGetSymmetricDifference(alpha: any[], beta: any[]): any[]
  • name

    arrayGetSymmetricDifference

    description

    Get array symmetric difference

    since

    0.1.35

    Parameters

    • alpha: any[]

      First array

    • beta: any[]

      Second array

    Returns any[]

    Array with difference

arrayGetUnique

  • arrayGetUnique(array: any[], sort?: boolean): any[]
  • name

    arrayGetUnique

    example

    arrayGetUnique([NaN, NaN, 0, -0, +0, "\u0065\u0301", "\u00e9"]) -> [ NaN, 0, 'eĢ', -0 ]

    Parameters

    • array: any[]
    • sort: boolean = true

    Returns any[]

arrayIsEmpty

  • arrayIsEmpty(array: any[]): boolean
  • name

    arrayIsEmpty

    Parameters

    • array: any[]

    Returns boolean

arrayKeyFirst

  • arrayKeyFirst<T>(array: T[]): null | number
  • name

    arrayKeyFirst

    Type parameters

    • T

    Parameters

    • array: T[]

    Returns null | number

arrayKeyLast

  • arrayKeyLast<T>(array: T[]): null | number
  • name

    arrayKeyLast

    Type parameters

    • T

    Parameters

    • array: T[]

    Returns null | number

arrayMakeClone

  • arrayMakeClone<T>(array: T[]): T[]
  • Type parameters

    • T

    Parameters

    • array: T[]

    Returns T[]

arrayMakeFrom

  • arrayMakeFrom(iterable: any): any[]
  • description

    Typecast variable to array

    Parameters

    • iterable: any

    Returns any[]

arrayMakeSum

  • arrayMakeSum(array: any[]): number
  • Parameters

    • array: any[]

    Returns number

arraySearchBinary

  • arraySearchBinary(array: number[], target: number): number
  • Parameters

    • array: number[]
    • target: number

    Returns number

arraySearchLinear

  • arraySearchLinear(array: number[], target: number): number
  • Parameters

    • array: number[]
    • target: number

    Returns number

arraySortBubble

  • arraySortBubble(array: number[]): number[]
  • name

    arraySortBubble

    Parameters

    • array: number[]

    Returns number[]

arraySortInsertion

  • arraySortInsertion(array: number[]): number[]
  • Parameters

    • array: number[]

    Returns number[]

arraySortMerge

  • arraySortMerge(array: number[]): number[]
  • Parameters

    • array: number[]

    Returns number[]

arraySortQuick

  • arraySortQuick(items: number[], left: number, right: number): number[]
  • Parameters

    • items: number[]
    • left: number
    • right: number

    Returns number[]

arraySortSelection

  • arraySortSelection(array: number[]): number[]
  • Parameters

    • array: number[]

    Returns number[]

Generated using TypeDoc