Hackerrank Day 16: Exceptions – String to Integer

screen-shot-2016-12-23-at-4-28-40-pm

My solution in Ruby:

This was a nice break from all the classes and inheritance stuff.  Basically did a brief overview of raising errors in this challenge.  I learned a bit about parsing an integer value from a string token with the following functions:

  • Java: Integer.parseInt(token)
  • C++: stoi(token)
  • Python: int(token)
  • Ruby: Integer(token)

screen-shot-2016-12-23-at-4-27-02-pm

More reading on Ruby Exceptions here and here.

Advertisements
Hackerrank Day 16: Exceptions – String to Integer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s