Remove Spaces and Tabs in a String
In this lesson, we'll learn how to remove tabs from a string using recursion.
We'll cover the following...
What does “Removing Tabs and Spaces from a String” mean?
Our task is to remove all tabs and spaces from a string. This includes the character \t
and " "
from a string.
Removing spaces from a string.
Implementation
Press + to interact
function remove(string) {// Base caseif (string.length == 0) {return "";}// Recursive caseif (string[0] == "\t" || string[0] == " ") {return remove(string.substr(1));}else {return string[0] + remove(string.substr(1));}}// Driver Codevar myString = "Hello\tWorld";console.log(remove(myString));
Explanation
Removing tabs from a null string ""
...