Question: Can someone please pseudocode this for me please? I can understand most of it but I get lost function polybius(input, encode = true) { const

Can someone please pseudocode this for me please? I can understand most of it but I get lost

function polybius(input, encode = true) {

const alphabet = {

a: 11,

b: 21,

c: 31,

d: 41,

e: 51,

f: 12,

g: 22,

h: 32,

"(i/j)": 42,

k: 52,

l: 13,

m: 23,

n: 33,

o: 43,

p: 53,

q: 14,

r: 24,

s: 34,

t: 44,

u: 54,

v: 15,

w: 25,

x: 35,

y: 45,

z: 55,

};

let result = "";

if (!input) return false;

if (encode) {

for (let i = 0; i < input.length; i++) {

const letter = input[i].toLowerCase();

if (letter === "i" || letter === "j") {

result += 42;

} else if (letter === " ") {

result += " ";

} else {

const pairs = Object.entries(alphabet).find(

(pair) => letter === pair[0]

);

result += pairs[1];

}

}

}

if (!encode) {

const checkLength = input.split(/\s/).join("");

if (checkLength.length % 2 !== 0) return false;

for (let i = 0; i < checkLength.length; i += 2) {

const firstIndex = input[i];

const secondIndex = input[i + 1];

const combinedIndex = firstIndex + secondIndex;

if (firstIndex === " ") {

result += " ";

i -= 1;

continue;

} else {

result += Object.keys(alphabet).find(

(key) => alphabet[key] == combinedIndex

);

}

}

}

return result;

}

return {

polybius,

};

})();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!