curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68b06e589bf2273243814773.md
Given a paragraph, return a new paragraph where the first letter of each sentence is capitalized.
.), one or more question marks (?), or one or more exclamation points (!).capitalize("this is a simple sentence.") should return "This is a simple sentence.".
assert.equal(capitalize("this is a simple sentence."), "This is a simple sentence.");
capitalize("hello world. how are you?") should return "Hello world. How are you?".
assert.equal(capitalize("hello world. how are you?"), "Hello world. How are you?");
capitalize("i did today's coding challenge... it was fun!!") should return "I did today's coding challenge... It was fun!!".
assert.equal(capitalize("i did today's coding challenge... it was fun!!"), "I did today's coding challenge... It was fun!!");
capitalize("crazy!!!strange???unconventional...sentences.") should return "Crazy!!!Strange???Unconventional...Sentences.".
assert.equal(capitalize("crazy!!!strange???unconventional...sentences."), "Crazy!!!Strange???Unconventional...Sentences.");
capitalize("there's a space before this period . why is there a space before that period ?") should return "There's a space before this period . Why is there a space before that period ?".
assert.equal(capitalize("there's a space before this period . why is there a space before that period ?"), "There's a space before this period . Why is there a space before that period ?");
function capitalize(paragraph) {
return paragraph;
}
function capitalize(paragraph) {
return paragraph.replace(/([.!?]+)(\s*)([a-z])/g, (match, punc, spaces, char) => {
return punc + spaces + char.toUpperCase();
})
.replace(/^([a-z])/, (match, char) => char.toUpperCase());
}