incomplete_Simple Sentences
codewars kata6.. try regex
by trentHarlem
HTML
Simple Sentences
Implement a function, so it will produce a sentence out of the given parts.
Array of parts could contain:
words;
commas in the middle;
multiple periods at the end.
Sentence making rules:
there must always be a space between words;
there must not be a space between a comma and word on the left;
there must always be one and only one period at the end of a sentence.
Example:
JavaScript
function makeSentence(parts) {
// period at end
parts.push('.')
// space between words
let sentence = parts.slice().join(' ').replace(' , ',', ');
// space between comma and word on left
// return parts
return sentence.replace(' .','.');
}
// splice(parts.length,0,'.')
console.log(makeSentence(['hello', ',', 'my', 'dear'])) // returns 'hello, my dear.'