/**
* Remove backspaces from a string
* @param {String} string
* @throws {Error} If the function gets called with more or less than one argument
* @throws {TypeError} If the function gets called with a non-string argument
* @return {String}
*/functioncleanString(string){if(arguments.length!==1){thrownewError("Expected exactly one argument.");}if(typeofstring!=="string"){thrownewTypeError("Expected first argument to be a string.");}constcharacters=[];for(constcharacterofstring){// If this is a characterif(character!=="#"){characters.push(character);continue;}// If this is a backspace character// And that there is at least one character if(characters.length){characters.pop();}}returncharacters.join("");}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
JavaScript