- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Reversing the alphabet from back to front and front to back in JavaScript
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
- Related Articles
- queue::front() and queue::back() in C++ STL
- list::front() and list::back() in C++ STL
- deque front( ) and deque back( ) in C++ in STL
- How to use both front and back cameras simultaneously in iOS?
- Program to convert linked list by alternating nodes from front and back in Python
- Program to implement a queue that can push or pop from the front, middle, and back in Python
- Program to find number of possible position in n-person line with few person at front and back in Python
- The animals called predators have:(a) both the eyes on the sides (b) one eye on the side and one at the front(c) one eye on the front and one at the back (d) both the eyes at the front
- Encoding decimal to factorial and back in JavaScript
- Think you are sitting in a chamber with your back to wall.An electron beam moving horizontally from back wall towards the front wall is deflected by a strong magnetic field to your right side. What is the direction of magnetic field?
- The animals of prey have:(a) two eyes at the front (b) two eyes at the back(c) two eyes on the sides (d) one eye at the front and one on the side
- Back-to-Back Test (Sumpner’s Test) on Transformer
- Imagine that you are sitting in a chamber with your back to one wall. An electron beam, moving horizontally from back wall towards the front wall, is deflected by a strong magnetic field to your right side. What is the direction of magnetic field?
- Sending response back from Node.js server to browser
- Shift certain array elements to front of array - JavaScript

Advertisements