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

89
Views
Array search strategy

The task is the following - in input there are some English letters which I want to replace by values located in jap and put in outputArr according to dictionary in eng (same position).

But I really don't understand how to make such loop / if to make it work.

<script>
var input = "agde";
var inputArr = input.split('');
var outputArr = [];
var eng= ["a","b","c","d","e","f","g"];
var jap = ["あ","び","を","ご","で","え","よ"];
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

First combine eng and jap into a lookup table (a plain object):

var eng = ["a","b","c","d","e","f","g"];
var jap = ["あ","び","を","ご","で","え","よ"];
var translation = Object.fromEntries(eng.map((letter, i) => [letter, jap[i]]));


// Now translate an example input
var input = "agde";
var output = Array.from(input, letter => translation[letter]).join("");
console.log(output);

about 4 years ago · Santiago Trujillo Report

0

You can map the array and use the indexOf method from Arrays to find the index of English alphabet and use it against the jap array

var input = "agde";
var eng= ["a","b","c","d","e","f","g"];
var jap = ["あ","び","を","ご","で","え","よ"];

const getJapOut = ([...input]) => [...input].map(value => jap[eng.indexOf(value)])

console.log(getJapOut(input));

about 4 years ago · Santiago Trujillo Report

0

You can make use of indexOf function to get the corresponding index, access it via [] and map the result into your outputArr:

var eng = ["a", "b", "c", "d", "e", "f", "g"];
var jap = ["あ", "び", "を", "ご", "で", "え", "よ"];

var input = "agde";
var inputArr = input.split("");

const outputArr = inputArr.map((char) => jap[eng.indexOf(char)]);
console.log(outputArr);

about 4 years ago · Santiago Trujillo 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!