Skip to content

Instantly share code, notes, and snippets.

@mrmlnc
Created March 30, 2017 12:24
Show Gist options
  • Save mrmlnc/a0b1a0914b0977d1202275f0952fb31f to your computer and use it in GitHub Desktop.
Save mrmlnc/a0b1a0914b0977d1202275f0952fb31f to your computer and use it in GitHub Desktop.
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