Reversing all alphabetic characters in JavaScript



Problem

We are required to write a JavaScript function that takes in a string str. The job of our function is to reverse it, omitting all non-alphabetic characters.

Example

Following is the code −

 Live Demo

const str = 'exa13mple'; function reverseLetter(str) {    const res = str.split('')    .reverse()    .filter(val => /[a-zA-Z]/.test(val))    .join('');    return res; }; console.log(reverseLetter(str));

Output

elpmaxe
Updated on: 2021-04-17T13:45:11+05:30

139 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements