We are required to write a JavaScript function that takes in a single alphabet as the only input. The function should compute the position of the that alphabet from starting and return an alphabet that’s at the same position but from the back.
Example
The code for this will be −
const alpha = 'g'; const findCounterPart = (alpha = '') => { let alphabet = 'abcdefghijklmnopqrstuvwxyz'; let firstpart = alphabet.substring(0,13).split(''); let secondpart = alphabet.substring(13).split('').reverse(); let solution = ''; if (firstpart.indexOf(alpha) !== −1) { solution = secondpart[firstpart.indexOf(alpha)]; } else { solution = firstpart[secondpart.indexOf(alpha)]; }; return solution; }; console.log(findCounterPart(alpha));
Output
And the output in the console will be −
t