Jordan Hudgens

242 Posts

  • Refactoring an Iterative XML Parser to Use Functional Programming in Ruby

    In the last guide I implemented an XML parser that counted all of the lines from Shakespeare’s Macbeth play. That implementation worked, however it used an iterative approach, which resulted in a highly coupled method that would only be able to work on another XML file if it had an identical structure and set of tag names. In this guide we’re going to refactor the solution to utilize a functional approach. Summary Refactor the Macbeth XML parser/counter so it uses a functional programming approach. Credit to Upcase for the great coding exercise. Exercise File Code […]

  • How to Sum XML Data and Converting it to a Hash in Ruby

    When it comes to working with APIs, two of the most common tools that you will use are JSON and XML. In this guide we’ll walk through a challenging task in which we ingest the full play of Shakespeare’s Macbeth in XML and convert it into a hash that sums the total number of lines for each character in the play. Credit to Upcase for the great coding exercise. Summary Build out a method that sums the total number of lines of each character in Macbeth. Exercise File Code File Exercise Description Implement a method […]

  • Convert an Array of File Require Statements into File Names

    When building scripts, it’s a common requirement to remove and update multiple items in a collection of strings. In this guide we’re going to mimic the process needed to take a list of require statements and generate a list of file names. Summary Implement a method that generates a list of file names based on a collection of require statements. Exercise File Code File Exercise Description Build a method that takes in an array of require statements and outputs an array of the file names with their JavaScript extension added. Example javascript_files = [ ‘//= […]

  • Working with Infinity in Ruby

    Working with infinity can be a unique challenge in many different programming languages. Thankfully Ruby offers a helpful library that allows you to implement infinity into programs, and that’s what this guide focuses on. Summary Build a method that utilizes infinity in order to generate a string based collection of any size. Exercise File Code File Exercise Description Leverage Ruby’s Infinity library in order to build a method that generates a collection of string based integers of any size provided by the method argument. Example string_infinity_generator 10 # => [“1”, “2”, “3”, “4”, “5”, “6”, […]

  • Build a File Type Hash Mapper in Ruby

    Whether it’s a complex coding interview question or algorithm implementation, there are many times where you will be asked to combine a large number of processes into a single feature. In this guide we’ll examine how to build a non-trivial program that takes in an array of file names and generates a hash collection where each file type is the key and the value is an array of their respective file names. Summary Build a method that takes in an array of file names and filters them into an organized hash. Exercise File Code File […]

  • Build an Array Method that Returns a List of Filenames for Specific File Types

    Parsing file types can be a complex process. However, by leveraging the grep method you can leverage regular expressions to quickly return a full list of all of the file types that you’re searching for. Summary Build a method that searches for specific file types. Exercise File Code File Exercise Description Add a method to the Array class that can look through an array of file names and return a filtered array with the file names for the file type searched for. Example file_names = %w{file1.rb file2.html file3.rb file4.rb file5.js} file_names.file_selector ‘rb’ # => [‘file1’, […]

  • Remove Anomalies in a Ruby Array

    When working with large data sets, you’ll discover that there are many times where your collections have anomalies that need to be removed. In this guide we’ll walk through how to easily remove any values lower or higher than a range of values. Summary Implement the ability to remove anomalies from a Ruby collection Exercise File Code File Exercise Description Given an array of integers, add a method to the array class that removes any/all values higher or lower than specified arguments. Standard Heredoc Example [44, 8043, 443, 43452, 2183].remove_anomalies 100, 10_000 # => [8043, […]

  • How to Use Indention with Multiline Strings with the Squiggly Heredoc Syntax

    Working with multiline strings in Ruby used to result in very odd looking code because heredocs required that you shift all of the string code so it was flush against the left hand side of the file. However, with modern versions of Ruby you are now able to utilize the squiggly heredoc syntax, which allows you to indent multiline strings in a file. Summary Refactor a multiline string in Ruby so that it can be indented. Exercise File Code File Exercise Description Given a multiline string, stored in a Ruby Heredoc, refactor it so that […]

  • Build a Baseball Scoreboard Program in Ruby

    This guide examines a seemingly simple program, however, in order to properly implement the solution, you will be required to use a number of key Ruby programming techniques. In this exercise, you’ll build out a scoreboard program that generates an inning by inning score for a baseball team along with a dynamic total. Summary Build a program that keeps track of a baseball team’s score on an inning by inning basis along with totaling up the total runs. Exercise File Code File Exercise Description Build a Ruby class that works like a scoreboard for a […]

  • Parse a String Based Date and Convert it Into a Ruby Date Object

    Working with dates in web applications can pose a unique challenge, especially when working with multiple date formats. This guide focuses on how to convert string based strings in a specific format into a Ruby date object so that you can utilize it in your own program. Summary Convert a string that contains a date and a specific format into a Ruby date object. Exercise File Code File Exercise Description Given a string date with the format mm/dd/yyyy, convert the string into a Ruby date object that can be treated like a date created directly […]

By Daniele Zedda • 18 February

← PREV POST

By Daniele Zedda • 18 February

NEXT POST → 34
Share on