Created
October 16, 2014 23:16
-
-
Save Karlina-Bytes/8ee90fdb1e45f787cbc0 to your computer and use it in GitHub Desktop.
A JavaScript function for removing spaces in a string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************* | |
* Removes space characters from the input string. | |
* @param {String} inputString | |
* @return {String} "cleaned up" inputString. | |
*********************************************************/ | |
function removeSpaces( inputString ) { | |
// If the inputString is empty, return an error. | |
if (!inputString) return "Error"; | |
/** | |
* For each character in inputString, | |
* if the character is NOT a space character, | |
* append it to the string to return. | |
*/ | |
var modifiedString = ""; | |
for (var i in inputString) | |
if (inputString[i] != " ") | |
modifiedString += inputString[i]; | |
// Return de-spaced string. | |
return modifiedString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment