S
S
scorpion111332020-08-15 16:16:08
JavaScript
scorpion11133, 2020-08-15 16:16:08

How to search for Ghbdtn and return results for HELLO (ReactJS)?

Hello everyone
How to make a multilingual search?
How to search for GHBDTN and return results for HELLO (ReactJS)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alekssamos, 2020-08-15
@alekssamos

You can make a dictionary like this:

var kb = {
  "q":"й",
  "w":"ц",
  "e":"у",
  "r":"к",
  "t":"е",
  "y":"н"
  // и дальше
};

And a function like this:
function chkb(s) {
  var ret = '';
  for(let i = 0; i < s.length; i++) {
    if(s[i] in kb) {
      ret = ret + kb[s[i]];
    } else {
      ret = ret + s[i];
}
  }
  return ret;
}

We check: First we search for the input, if there is nothing, then we transform it. console.log( chkb("qwer") ); // йцук

M
Maxim Bredikhin, 2020-08-16
@MaximBredikhin

const dictionary = {
    q: 'й',
    w: 'ц',
    // ...
};

const toRoman = str => [...str].reduce((acc, cur) => [...acc, dictionary[cur]], []).join('');

Something like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question