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

[Codewars] Convert a String to a Number! (8 kyu) / JavaScript

by fluss 2022. 10. 10.

https://www.codewars.com/kata/544675c6f971f7399a000e79

 

Codewars - Achieve mastery through coding practice and developer mentorship

Coding practice 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:

Note: This kata is inspired by Convert a Number to a String!. Try that one too.

Description

We need a function that can transform a string into a number. What ways of achieving this do you know?

Note: Don't worry, all inputs will be strings, and every string is a perfectly valid representation of an integral number.

 

Examples

"1234" --> 1234
"605"  --> 605
"1405" --> 1405
"-7" --> -7

 

설명:

참고: 이 카타는 Convert a Number to a String!에서 영감을 받았습니다. 이것도 시도해보세요.

설명

문자열을 숫자로 바꾸는 함수가 필요합니다. 이것을 성취하는 어떠한 방법을 알고 있습니까?

참고: 걱정하지 마세요. 모든 입력은 문자열일 것이고 모든 문자열은 정수의 완벽하게 유효한 표현입니다.

 

예시

"1234" --> 1234
"605"  --> 605
"1405" --> 1405
"-7" --> -7

 

풀이

const stringToNumber = function(str){
  return Number(str);
}

댓글