CronDose | Daily Dev Guides

Daily Snippets for the Developer Life

Find All Potential Products in Ruby

This guide examines how to properly find the full set of potential products in a Ruby collection. Summary Build a method that returns all of the divisible items of two integers. Exercise File Code File Exercise Description Implement a method that returns all of the potential products of two integers in Ruby up through a certain range. Sample Input 1..120000 # range 200 # number 1 73 # number 2 Expected Output [14600, 29200, 43800, 58400, 73000, 87600, 102200, 116800] Real World Usage This exercise will test your knowledge of how to work with the […]

Find the Largest Words in an Array in Ruby

Learn how to build a method that returns the largest words in an array in a Ruby program. Summary Implement a method that finds the largest words in a Ruby array. Exercise File Code File Exercise Description Given a number and an array of strings, find the largest strings in an array. Sample Input Given an array of strings: %w{a group of words that are variable length} And a number of the largest items: 3 Expected Output [“variable”, “length”, “words”] Real World Usage This is a common skill when it comes to working with data […]

Using Ruby’s Detect Method to Find Divisible Numbers

In this guide you’ll learn how to find divisible numbers by leveraging Ruby’s detect method. Summary Build a method that finds the first divisible number of two integers. Exercise File Code File Exercise Description Given two integers, build a method that returns the first number that is divisible by both numbers. Sample Input Given the numbers: 12, 16 Expected Output 48 Real World Usage Finding divisible numbers is a common coding interview question. Additionally, it’s an important concept when working with mathematical equations. Solution Can be found on the solutions branch on github.

Markdown Heading Parser in Ruby with Heredocs

This guide examines how to parse a Ruby Heredoc object and convert any lines with a hashtag to HTML H1 headings. Summary Parse a Ruby Heredoc and replace any lines that start with a hashtag with HTML H1 heading tags. Exercise File Code File Exercise Description Given a Ruby Heredoc string, replace any lines that start with a hashtag and wrap them in HTML H1 heading tags. Sample Input content = <<-EOF # Hey there Some content # Another heading More content EOF Expected Output “<h1>Hey there</h1>\n\nSome content\n\n<h1>Another heading</h1>\n\nMore content\n” Real World Usage When it […]

Calculate the Nth Fibonacci Number from a Sequence

This guide walks through how to work with the Fibonacci sequence and return the final from a list of Fibonacci numbers. Summary Build a method that returns the nth Fibonacci number. Exercise File Code File Exercise Description Build a method that takes in a number, that represents┬án and returns the nth Fibonacci number in the sequence. Sample Input nth_fibonacci 10 Expected Output 89 Real World Usage The Fibonacci sequence is critical for a number of algorithm implementations, this guide walks through how to pick out specific Fibonacci numbers. Solution Can be found on the solutions […]

Fibonacci Sequence Generator in Ruby

In this guide, we’ll walk through how to generate the Fibonacci sequence in the Ruby programming language. Summary Create a method that generates the Fibonacci sequence. Exercise File Code File Exercise Description Build a method that returns an array of the Fibonacci sequence of a pre-defined number of values. Sample Process Definition: Characterized by the fact that every number after the first two is the sum of the two preceding ones. fibonacci 10 Expected Output [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] Real World Usage The Fibonacci sequence is a […]

How to Sort the Keys of a Hash in Ruby

This guide walks through how to work with Ruby hashes, specifically how to sort through the keys by length. Summary Build a method that sorts the keys in a hash by length. Exercise File Code File Exercise Description Given a Ruby Hash, build a method that returns an array of keys that are sorted based on length. Sample Input { some_key: ‘Anything’, “string key” => ‘Anything’, 8383 => ‘Does not matter’ } Expected Output [“8383”, “some_key”, “string key”] Real World Usage Working with hashes in Ruby is critical when it comes to performing tasks such […]

Build a Breadcrumb Generator in Ruby

This guide walks through how to build a breadcrumb generator that converts an array to a slash-separated string. Summary Create a method that builds a breadcrumb based navigation. Exercise File Code File Exercise Description Given an array of strings, build a method that converts the strings into a single string where each element is separated by a /. Sample Input [‘String 1’, ‘String 2’, ‘String 3’] Expected Output ‘String 1 / String 2 / String 3′ Real World Usage When it comes to building Rails applications, it’s a common requirement to implement view helper methods. […]

Generating a Sum of Prime Numbers in Ruby

This guide walks through how to generate a sum of prime numbers in Ruby. Summary Create a method that totals a sequence of prime numbers. Exercise File Code File Exercise Description After being provided with a number, generate a sequence of prime numbers that are greater than or equal to the given number, and then return the total of the prime numbers. Sample Input 42 Expected Output 238 Real World Usage Prime numbers are important in a number of computer science fields, including: security and linear mathematical implementations. This guide will test your knowledge of […]

Remove Vowels from an Array in Ruby

In this guide we’ll examine how to remove all of the vowels from an array in Ruby by leveraging regular expressions. Summary Build a method that removes the vowels from a Ruby collection. Exercise File Code File Exercise Description Given the following array of strings: [‘a’, ‘b’, ‘c’] Build a method that removes the vowels from a Ruby array. Expected Output [‘b’, ‘c’] Real World Usage There are a number of ways to implement this solution. One of the most efficient is to utilize regular expressions. When it comes to parsing string data, using regular […]

By Daniele Zedda • 18 February

← PREV POST

By Daniele Zedda • 18 February

NEXT POST → 34
Share on