Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/textCleaning.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ function removeWhitespace(string) {
Expected Output: 'HelloWorldfromSTRINGUtils!'
Clear the space clutter! Write your code and export the function.
*/
let stringWithoutSpace = "";
for(let i=0; i<string.length; i++) {
if(string[i] !== " ") {
stringWithoutSpace += string[i];
}
}
return stringWithoutSpace;
}

// Grouped exports
export { trimStart, trimEnd, normalizeWhitespace };
export { trimStart, trimEnd, normalizeWhitespace, removeWhitespace };
17 changes: 17 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
invertCase,
extractHashtags,
formatTime,
removeWhitespace
} from "../index";

describe("capitalize", () => {
Expand Down Expand Up @@ -119,6 +120,7 @@ describe("invertCase", () => {
test("Check for String with Newline and Tab Characters", () => {
expect(invertCase("Hello\n\tWorld")).toBe("hELLO\n\twORLD");
});
});

describe("maskPhone", () => {
test("masks phone number with default visibleDigits", () => {
Expand Down Expand Up @@ -173,3 +175,18 @@ describe("formatTime", () => {

// More test for formatTime...
});

describe("Testing the removeWhitespace function", () => {
test("Adding whitespace in front of the string", () => {
expect(removeWhitespace(" HelloWorld!")).toBe("HelloWorld!");
})
test("Adding whitespace in end of the string", () => {
expect(removeWhitespace("HelloWorld! ")).toBe("HelloWorld!");
})
test("Adding whitespace only in between the words of the string", () => {
expect(removeWhitespace("Hello World!")).toBe("HelloWorld!");
})
test("Adding whitespace in between of the string", () => {
expect(removeWhitespace(" Hello World! ")).toBe("HelloWorld!");
})
})