(알고리즘) CodeWars : Thinkful - String Drills: Poem formatter

호두파파·2021년 6월 10일
0

알고리즘 연습

목록 보기
15/60
post-thumbnail

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:

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");
}
profile
안녕하세요 주니어 프론트엔드 개발자 양윤성입니다.

0개의 댓글