Function trimEnd

  • Removes the trailing end characters from a string.

    Time complexity: O(n)

    Space complexity: O(n)

    Parameters

    • string: string

      The string to trim

    • end: string

      The character to remove from the end of string

    Returns string

    A string with the leading end characters removed

    trimEnd('aabbcc', 'c'); // 'aabb'
    

    (trimStart:1) to do the same thing but trim from the start of a string

    String

  • Removes the trailing end characters from an array.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • array: readonly T[]

      The array to trim

    • end: T

      The character to remove from the end of array

    Returns T[]

    A shallow-copied array with the trailing start characters removed

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

    (trimStart:2) to do the same thing but trim from the start of an array

    Array