Created
March 30, 2017 12:24
-
-
Save mrmlnc/a0b1a0914b0977d1202275f0952fb31f to your computer and use it in GitHub Desktop.
This file contains 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
const str = ' some string '; | |
function normalize(input: string): string { | |
let length = input.length; | |
let i = 0; | |
while (i < length - 1) { | |
const char: string = input[i]; | |
const nextChar: string = input[i + 1]; | |
if (char === ' ' && nextChar === ' ') { | |
input = input.substr(0, i) + ' ' + input.substr(i + 2); | |
length - 1; | |
continue; | |
} | |
i++; | |
} | |
return input; | |
} | |
console.log(normalize(str)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment