Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sergey Volkov #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Sergey Volkov #11

wants to merge 5 commits into from

Conversation

WERT7
Copy link

@WERT7 WERT7 commented Oct 16, 2016

Щепотка костылей, и всё работает

function translitToRu(str) {
let newStr = '';
for (let i = 0; i < str.length; i++) {
switch (str[i]) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Привет. Здесь ты берешь из строки str[i], а дальше в коде сравниваешь с сочетаниями символов (ja, ju, ...).
В str[i] попадет всегда один символ, и проверки не сработают, как надо.
Switch/case здесь не самое оптимальное решение. Можно сделать сильно проще, если хранить соответствие замен одних символов в другие в массиве, например, а сами замены делать, например, так: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/replace

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо, тоже к этому пришёл )


var Transform = require('stream').Transform;

var engSubstringsToReplace =
Copy link

@govorov govorov Oct 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы сделал

[
    {'Shh' : 'Щ'},
    {'Jo':'Ё'},
    {'Zh':'Ж'},
    {'Ch':'Ч'},
...
]

Чтобы не приходилось заморачиваться с порядком элементов в двух массивах. Тем более исходные данные уже примерно в таком формате.

app.listen(PORT, () => console.log(`App is listen on ${PORT}`));

// IMPORTANT
module.exports = app;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В конце файла не хватает перевода строки)
http://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants