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