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

147
Views
Polybius Square Javascript Map Function

I'm working on a problem solving a polybius square functionality. I am having trouble figuring out how to create a polybius square function. with the following instructions:

The polybius() function in the src/polybius.js file has two parameters:

input refers to the inputted text to be encoded or decoded. encode refers to whether you should encode or decode the message. By default it is set to true . When building the function, keep the following constraints and rules in mind:

You are welcome to assume that no additional symbols will be included as part of the input. Only spaces and letters will be included. When encoding, your output should still be a string. When decoding, the number of characters in the string excluding spaces should be even. Otherwise, return false . Spaces should be maintained throughout. Capital letters can be ignored. The letters "I" and "J" share a space. When encoding, both letters can be converted to 42 , but when decoding, both letters should somehow be shown.

& basically, I got to here with my code:

    const cipher = (input, encode = true) => {
  const direction = encode ? encoder : decoder;

  return input
    .match(/[0-9]{2}|[a-z]|\s/g)
    .map(character => direction[character] || character)
    .join('');
};

but i'm lost on how I would do this for the i/j exception when I am decoding a string. Any thoughts?

    const encoder = { 'a': '11', 'b': '12', 'c': '13', 'd': '14', 'e': '15', 'f': '21', 'g': '22', 'h': '23', 'i/j': '24', 'k': '25', 'l': '31', 'm': '32', 'n': '33', 'o': '34', 'p': '35', 'q': '41', 'r': '42', 's': '43', 't': '44', 'u': '45', 'v': '51', 'w': '52', 'x': '53', 'y': '54', 'z': '55' };
const decoder = { '11': 'a', '12': 'b', '13': 'c', '14': 'd', '15': 'e', '21': 'f', '22': 'g', '23': 'h', '24': 'i/j', '25': 'k', '31': 'l', '32': 'm', '33': 'n', '34': 'o', '35': 'p', '41': 'q', '42': 'r', '43': 's', '44': 't', '45': 'u', '51': 'v', '52': 'w', '53': 'x', '54': 'y', '55': 'z' };

TL:DR -> Need to figure out how to use the .map function for i/j exception for decoding a polybius string

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

0

Try with these:

var txt=txt.toLowerCase().replace('j','i') 
var r='' 
for(var a=0;a0){ 
    if(t.substr(0,1)==' '){ 
        r+=' ' 
        c=1 
    } 
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!