Function trimStart

  • Category

    Removes the leading start characters from a string.

    Time complexity: O(n)

    Space complexity: O(n)

    Parameters

    • string: string

      The string to trim

    • start: string

      The character to remove from the start of string

    Returns string

    A string with the leading start characters removed

    trimStart('aabbcc', 'a'); // 'bbcc'
    

    (trimEnd:1) to do the same thing but trim from the end of a string

    String

  • Category

    Removes the leading start characters from an array.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • array: readonly T[]

      The array to trim

    • start: T

      The character to remove from the start of array

    Returns T[]

    A shallow-copied array with the leading start characters removed

    trimStart(['a', 'a', 'b', 'b', 'c', 'c'], 'a'); // ['b', 'b', 'c', 'c']
    

    (trimEnd:2) to do the same thing but trim from the end of an array

    Array