본문 바로가기
알고리즘/Codewars

[Codewars] Simple Fun #176: Reverse Letter (7 kyu) / JavaScript

by fluss 2023. 2. 3.

https://www.codewars.com/kata/58b8c94b7df3f116eb00005b

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

Task

Given a string str, reverse it and omit all non-alphabetic characters.

 

Example

For str = "krishan", the output should be "nahsirk".

For str = "ultr53o?n", the output should be "nortlu".

 

Input/Output

  • [input] string str

A string consists of lowercase latin letters, digits and symbols.

  • [output] a string

 

코드

function reverseLetter(str) {
  return str.replace(/[^a-z]/ig, "").split('').reverse().join('');
}

댓글