(アルゴリズム)CodeWars:Thinkful-String Drills:Poem formatter
1986 ワード
Description:
You have a collection of lovely poems. Unfortuantely they aren't formatted very well. They're all on one line, like this:
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated.
What you want is to present each sentence on a new line, so that it looks like this:
Tip
Try to solve this challenge with the str.split() and the str.join() string methods.
Every sentence will end with a period, and every new sentence will have one space before the previous period. Be careful about trailing whitespace in your solution.
問題を解く
ヒントに示すように,split()とjoin()法を適用して解くことができる.
You have a collection of lovely poems. Unfortuantely they aren't formatted very well. They're all on one line, like this:
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated.
What you want is to present each sentence on a new line, so that it looks like this:
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Write a function, format_poem()
that takes a string like the one line example as an argument and returns a new string that is formatted across multiple lines with each new sentence starting on a new line when you print it out.Tip
Try to solve this challenge with the str.split() and the str.join() string methods.
Every sentence will end with a period, and every new sentence will have one space before the previous period. Be careful about trailing whitespace in your solution.
問題を解く
ヒントに示すように,split()とjoin()法を適用して解くことができる.
function formatPoem(poem) {
//your code here
return poem.split(". ").join(".\n");
}
Reference
この問題について((アルゴリズム)CodeWars:Thinkful-String Drills:Poem formatter), 我々は、より多くの情報をここで見つけました https://velog.io/@yunsungyang-omc/Codewars-Thinkful-String-Drills-Poem-formatterテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol