Created
April 10, 2018 21:46
-
-
Save Lodo4ka/e870dfd0e9e4be4d2b04e596762921e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { length, toUpperCase } from './strings'; | |
// BEGIN (write your solution here) | |
export default (str) => { | |
let result = ""; | |
for(let i = 0; i < length(str); i++) { | |
const shouldBeBig = str[i] !== " " && (i === 0 || str[i - 1] === " "); | |
result += shouldBeBig ? toUpperCase(str[i]) : str[i]; | |
} | |
return result; | |
} | |
Реализуйте и экспортируйте по умолчанию функцию, которая делает заглавной первую букву каждого слова в предложении. | |
solution('hello, world!'); // Hello, World! | |
Подсказки | |
Вычисление длины строки: length(str). | |
Перевод строки/буквы в верхний регистр: toUpperCase(str). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment