Giter Club home page Giter Club logo

padawan-coding-exercises-no-04's Introduction

Coding Exercises No. 04

  1. Go through the ruby String documentation and look for a method or function that prepends or combine one string to another string. Using said method prepend the string "Learning " to the string "Ruby".

  2. Go through the ruby String documentation and look for a method or function that remove characters from a string. Using said method, it turns the string "Learning Ruby" into the string "Lrnng Rby".

  3. There is a ruby String method that allows to justify a string, padding it with another string. Find said method and use it on the string "Ruby" together with "<3" so that you get the following string result:

"Ruby<3<3<3"
  1. Create a ruby application called exercise_04.rb. Fill it in with the following lines:
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# your code goes here...

So that, when you run your code, e.g., ruby exercise_04.rb, you get the following output

5
  1. Copy exercise_04.rb to exercise_05.rb, then open this new file. Add another line before the line that you just added, so that, when you run your code you get the following output:
55
  1. Create a new ruby file called exercise_06.rb, and fill in the following line:
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# your code goes here...
puts numbers.inspect

So that you get the following output:

[2, 4, 6, 8, 10]

Tip: Consult the ruby Array documentation for the correct method or function to use.

  1. Again, copy the finished exercise_06.rb to exercise_07.rb.

Now change the code so that you get the following output:

[10, 8, 6, 4, 2]

Tip: Consult the ruby Array documentation for the correct method or function to use.

Note: The method select that you used in the last exercise returns an array. On this array (the returned value) you can use another method by appending another dot ., and the method that would produce the output [10, 8, 6, 4, 2].

Note: There is another method that reverses the order of the array. You can find it by googling for “ruby array reverse”.

  1. Again, copy the finished exercise_07.rb, then change your code so that you get the following output:
[10, 8, 4, 2]

Tip: Consult the ruby Array documentation for the correct method or function to use.

Bonus: Find at least three different solutions for this last change.

  1. Create a new file called exercise_09.rb, and fill the following lines:
dictionary = { :one => "ichi", :two => "ni", :three => "san" }
# your code goes here...

So that it prints out

ni
  1. Create a new file called exercise_10.rb and fill in the following line:
dictionary = { :one => "ichi", :two => "ni", :three => "san" }
# your code goes here...
puts dictionary[:four]

So that it prints out

shi

padawan-coding-exercises-no-04's People

Contributors

vulcansmithy avatar

Watchers

 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.