알고리즘 57 - Jaden Casing Strings
Q.
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"
A)
String.prototype.toJadenCase = function () {
return this.split(' ').map(el => {
let result = "";
for (let i = 0; i < el.length; i++) {
if (i === 0) {
result += el[i].toUpperCase()}
else {
result += el[i]}
}
return result}).join(' ');
};
other
String.prototype.toJadenCase = function () {
return this.split(' ').map(el => {
let result = "";
for (let i = 0; i < el.length; i++) {
if (i === 0) {
result += el[i].toUpperCase()}
else {
result += el[i]}
}
return result}).join(' ');
};
.slice(1)
를 이용해서 간단하게 첫알파벳만 빼고 붙여줄 수 있다.
String.prototype.toJadenCase = function() {
return this.split(' ').map(item => item[0].toUpperCase() + item.slice(1)).join(' ')
};
Author And Source
이 문제에 관하여(알고리즘 57 - Jaden Casing Strings), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@pearpearb/알고리즘-57-Jaden-Casing-Strings저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)