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

[Codewars] Get number from string (8 kyu) / JavaScript

by fluss 2023. 4. 25.

https://www.codewars.com/kata/57a37f3cbb99449513000cd8

 

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:

Write a function which removes from string all non-digit characters and parse the remaining to number. E.g: "hell5o wor6ld" -> 56

Function:

getNumberFromString(s)
 

코드

function getNumberFromString(s) {
  return Number(s.replace(/\D/g, ''));
}

댓글