OOP in JavaScript



  • There's a "majakaj" line, and we need to replace a cyrillian with a Latin to finally get a "majak."

    Code itself. "маяк". transliterate(); //должно вернуть "majak"

    How to fulfil this function and what will be called transliterate()?



  • What am I saying?

    In the end, my code was as follows:

    var item = {city:['Vashington','Moskva','Erevan']};

    var trans = function() {
        var
            rus = "щ   ш  ч  ц  ю  я  ё  ж  ъ  ы  э  а б в г д е з и й к л м н о п р с т у ф х ь".split(/ +/g),
            eng = "shh sh ch cz yu ya yo zh `` y' e` a b v g d e z i j k l m n o p r s t u f x `".split(/ +/g)
        ;
        return function(engToRus) {
            var x,
            text = this;
            for(x = 0; x < rus.length; x++) {
                text = text.split(engToRus ? rus[x] : eng[x]).join(engToRus ? eng[x] : rus[x]);
                text = text.split(engToRus ? rus[x].toUpperCase() : eng[x].toUpperCase()).join(engToRus ? eng[x].toUpperCase() : rus[x].toUpperCase());
            }
            return text;
        }
    };
    

    Object.prototype.transliterate = trans();

    for(var i = 0; i < Object.keys(item.city).length; i++) {
    console.log(item.city[i].transliterate());
    }

    P.S. Thanks for the answers.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2