Coder Social home page Coder Social logo

ruby-enumerables-practice-programming-languages-lab's Introduction

Nested Data Structures Practice: Iterating and Manipulating

Objectives

  1. Practice iterating over nested data structures
  2. Practice building nested data structures

Instructions

In this lab, you'll be coding your solution in programming_languages.rb. The reformat_languages method takes in an argument of languages and the test suite will call it with an argument of the below hash:

You are given a hash where the keys are the styles of the languages and the values are also hashes. These nested hashes have a key of the name of the language and value of the languages attributes, which is also a hash. These inner-most hashes have key/value pairs of type and type value. Take a look:

languages = {
  :oo => {
    :ruby => {
      :type => "interpreted"
    },
    :javascript => {
      :type => "interpreted"
    },
    :python => {
      :type => "interpreted"
    },
    :java => {
      :type => "compiled"
    }
  },
  :functional => {
    :clojure => {
      :type => "compiled"
    },
    :erlang => {
      :type => "compiled"
    },
    :scala => {
      :type => "compiled"
    },
    :javascript => {
      :type => "interpreted"
    }
 
  }
}

This is the hash you will be operating on and reformatting, programmatically––meaning you will not simply re-write the hash in order to get the tests passing.

Iterate over the hash and build a new hash that has the languages as keys that point to a value of a hash that describes the type and style.

It should match the following format:

{
  :ruby => {
    :type => "interpreted",
    :style => [:oo]
  },
  :javascript => {
    :type => "interpreted",
    :style => [:oo, :functional]
  },
  :python => {
    :type => "interpreted",
    :style => [:oo]
  },
  :java => {
    :type => "compiled",
    :style => [:oo]
  },
  :clojure => {
    :type => "compiled",
    :style => [:functional]
  },
  :erlang => {
    :type => "compiled",
    :style => [:functional]
  },
  :scala => {
    :type => "compiled",
    :style => [:functional]
  }
}

Tips:

  • Start by setting a variable, let's call it new_hash equal to an empty hash. Throughout your iteration over the languages hash, you can then add new key/value pairs to new_hash. At the end of your method, return new_hash.
  • Remember that you can create key/value pairs by using the []= method on a hash. For example:
hash = {}
hash[:my_key] = "my value"

puts hash
#  => {my_key: "my value"}

What if we want to create a key/value pair where the value is yet another hash?

hash = {}
hash[:my_key] = {second_level_key: "second level value"}

puts hash
#  => 
{
  my_key: {
     second_level_key: "second level value"
  }
}
  • Remember that you can add items to array using the << method.
  • Remember to use binding.pry to dig into your method and each level of the iteration. Play around with it inside the console. This will help you get the tests passing.

Resources

Arrays

Hashes

ruby-enumerables-practice-programming-languages-lab's People

Contributors

ahimmelstoss avatar aviflombaum avatar blake41 avatar deniznida avatar fislabstest avatar fs-lms-test-bot avatar kthffmn avatar maxwellbenton avatar nigelfloe avatar sarogers avatar sophiedebenedetto avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.