Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 1x 6x 7x 6x 23x 23x 19x | // https://www.codewars.com/kata/5202ef17a402dd033c000009
export function titleCase(title: string, minorWords?: string): string {
const titleArr = title.split(' ');
const minorWordsArr = minorWords && minorWords.split(' ').map(w => w.toLowerCase());
return titleArr
.map((word, index) => {
const newWord = word.toLowerCase();
return minorWordsArr && minorWordsArr?.includes(newWord)
? index === 0
? upperFirst(newWord)
: newWord
: upperFirst(newWord);
})
.join(' ');
}
const upperFirst = (word: string) => word.replace(/\w{1}/, match => match.toUpperCase());
|