7 kyu
String to integer conversion
2,055 of 4,480Uraza
Description:
JavaScript provides a built-in parseInt method.
It can be used like this:
"10"
returns10
"10 apples"
also returns10
We would like it to return "NaN"
(as a string) for the second case because the input string is not a valid number.
You are asked to write a function with the following rules:
- It should make the conversion if the given string only contains a single integer value (and possibly spaces - including tabs, line feeds... - at both ends)
- For all other strings (including the ones representing float values), it should return NaN
- It should assume that all numbers are not signed and written in base 10
Strings
Regular Expressions
Fundamentals
Similar Kata:
Stats:
Created | Mar 9, 2015 |
Published | Mar 9, 2015 |
Warriors Trained | 11010 |
Total Skips | 1652 |
Total Code Submissions | 35250 |
Total Times Completed | 4480 |
JavaScript Completions | 2013 |
CoffeeScript Completions | 39 |
Ruby Completions | 484 |
Python Completions | 2055 |
Total Stars | 113 |
% of votes with a positive feedback rating | 87% of 601 |
Total "Very Satisfied" Votes | 472 |
Total "Somewhat Satisfied" Votes | 103 |
Total "Not Satisfied" Votes | 26 |