Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
How do I convert double Latin letters?

How do I make sure that double letters are converted correctly? For example I want aa to become 2a instead of 1a1a.

var trans = {
  "a": "1a", 
  "aa": "2a",
  "e": "1e",
  "ee": "2e",
  "o": "1o",
  "oo": "2o",
}

function transliterate() {
  var latin = document.getElementById('latin').value;
  var result = '';
  var i;
  for (i = 0; i < latin.length; i++) {
    if (trans[ latin[i]] ) {
      result += trans[ latin[i]];
    }
  }
  document.getElementById('result').innerHTML = result;
  return false;
}

document.getElementById('latin').addEventListener('keyup', transliterate);
<input type="text" id="latin" />

<div id="result"></div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You will need to enforce your order of priority, like here:

var trans = {
  "a": "1a", 
  "aa": "2a",
  "e": "1e",
  "ee": "2e",
  "o": "1o",
  "oo": "2o",
}

let keys = ["aa", "ee", "oo", "a", "e", "o"];

function splitItems(input, index) {
    let temp = input.split(keys[index]);
    if (index + 1 === keys.length) return temp.join(trans[keys[index]]);
    let output = [];
    for (let item of temp) output.push(splitItems(item, index + 1));
    return output.join(trans[keys[index]]);
}

function transliterate() {
  var latin = splitItems(document.getElementById('latin').value, 0);
  document.getElementById('result').innerHTML = latin;
  return false;
}

document.getElementById('latin').addEventListener('keyup', transliterate);
<input type="text" id="latin" />

<div id="result"></div>

EDIT

To be clear, the test case has this result:

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!