Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lodo4ka/e870dfd0e9e4be4d2b04e596762921e0 to your computer and use it in GitHub Desktop.
Save Lodo4ka/e870dfd0e9e4be4d2b04e596762921e0 to your computer and use it in GitHub Desktop.
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