Removes the trailing end characters from a string.
end
Time complexity: O(n)
Space complexity: O(n)
The string to trim
The character to remove from the end of string
string
A string with the leading end characters removed
trimEnd('aabbcc', 'c'); // 'aabb' Copy
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.
The array to trim
The character to remove from the end of array
array
A shallow-copied array with the trailing start characters removed
start
trimEnd(['a', 'a', 'b', 'b', 'c', 'c'], 'c'); // ['a', 'a', 'b', 'b'] Copy
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
Removes the trailing
end
characters from a string.Time complexity: O(n)
Space complexity: O(n)