https://www.codewars.com/kata/5390bac347d09b7da40006f6
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
Jaden Smith, the son of Will Smith, is the star of films such as The Karate Kid (2010) and After Earth (2013). Jaden is also known for some of his philosophy that he delivers via Twitter. When writing on Twitter, he is known for almost always capitalizing every word. For simplicity, you'll have to capitalize each word, check out how contractions are expected to be in the example below.
Your task is to convert strings to how they would be written by Jaden Smith. The strings are actual quotes from Jaden Smith, but they are not capitalized in the same way he originally typed them.
Example:
Not Jaden-Cased: "How can mirrors be real if our eyes aren't real"
Jaden-Cased: "How Can Mirrors Be Real If Our Eyes Aren't Real"
Link to Jaden's former Twitter account @officialjaden via archive.org
설명:
윌 스미스의 아들인 제이든 스미스는 The Karate Kid (2010), After Earth (2013)와 같은 영화 스타입니다. 제이든은 트위터를 통해 전달하는 그의 철학으로도 유명합니다. 트위터에 글을 쓸 때 그는 거의 모든 글자를 대문자로 쓰는 것으로 알려져있습니다. 간단하게 하기 위해 모든 단어를 대문자로 나타내야 합니다. 아래의 예시에서 어떻게 축약이 예상되는지를 확인하세요.
문자열을 제이든 스미스가 작성하는 방식으로 바꾸세요. 문자열은 제이든 스미스의 실제 인용문이지만 그가 원래 입력한 것과 같은 방식으로 대문자로 표시되지 않습니다.
예시:
Not Jaden-Cased: "How can mirrors be real if our eyes aren't real"
Jaden-Cased: "How Can Mirrors Be Real If Our Eyes Aren't Real"
Link to Jaden's former Twitter account @officialjaden via archive.org
풀이
공백을 기준으로 문자열을 나눈다음 map으로 원소의 첫 글자를 대문자로 바꾸고 나머지 글자를 붙여주었다.
코드
String.prototype.toJadenCase = function () {
return this.split(' ').map(el => el[0].toUpperCase() + el.slice(1)).join(' ');
};
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Path Finder #1: can you reach the exit? (4 kyu) / JavaScript (0) | 2022.11.24 |
---|---|
[Codewars] Shortest Word (7 kyu) / JavaScript (0) | 2022.11.23 |
[Codewars] Duplicate Encoder (6 kyu) / JavaScript (0) | 2022.11.21 |
[Codewars] Exes and Ohs (7 kyu) / JavaScript (0) | 2022.11.19 |
[Codewars] Counting Duplicates (6 kyu) / JavaScript (0) | 2022.11.18 |
댓글