Continuing on with the theme of numbers, can you reimplement a basic implementation of parseInt? Our function will take in a string and return an integer representation of that string if one exists. Otherwise you can throw an error or return not a number. It's safe to assume that the input will be of base 10 but for bonus points I encourage you to support multiple bases as does the real parseInt.
parseInt('444') -> 444 parseInt('J3110') -> throw error or return NaN
Comments:
Anonymous - 10 years, 1 month ago
Only works for base 10 so no bonus points
reply permalink
Anonymous - 10 years, 1 month ago
C++:
reply permalink
asheehan - 10 years, 1 month ago
in Ruby:
can replace the #unpack with #ord on newer versions of Ruby.
reply permalink
bumbleguppy - 10 years, 1 month ago
Although deprecated, I will allow octal notation
reply permalink