π
String to Number
String to Numberμ
λ¬Έ κΈ°μ΄ λ¬Έλ² +5pts
Problem
Write a function that converts a string to a number.
Examples
Input:
stringToNum("42")Output:
42Explanation
μ΄ λ¬Έμ λ **λ¬Έμμ΄μ μ«μλ‘ λ³ν**νλ λ°©λ²μ νμ΅ν©λλ€. JavaScriptμμ μμ£Ό μ¬μ©λλ μ€μν λ³νμ λλ€. **Number() ν¨μ** λ¬Έμμ΄μ μ«μλ‘ λ³νν©λλ€: - Number("42") β 42 - Number("3.14") β 3.14 - Number("abc") β NaN **parseInt()μ parseFloat()** - parseInt("42px") β 42 (μ«μ λΆλΆλ§ μΆμΆ) - parseFloat("3.14em") β 3.14 - parseInt("abc") β NaN **λ¨ν + μ°μ°μ** ...
View detailed explanation βKey Concepts
Number() ν¨μ parseInt/parseFloat νμ
λ³ν NaN μ²λ¦¬
Time: O(n) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.