Git Product home page Git Product logo

fa15-hw1's Introduction

Rails Decal Fall 2015 Homework 1

This homework assignment involves writing scripts in ruby in order to get a feel for the Ruby programming language.

Q1

In hw1.rb there is a function called check_squared_sum. It function takes two integers, a and b, and calculates the sum of a and b, then returns the square of the sum.

Q2

The second method you have to fill in is sort_array_plus_one. This method takes in an array of integers, sorts it, then increments every element by 1, and returns it. It does not matter if this method is destructive or not.

Q3

The third method takes in two strings, a first_name and last_name. It will return the first_name concatenated with the last_name, along with a space in between.

Example:

combine_name 'Howard', 'Chen'
 => 'Howard Chen'

Q4

It's blockin' time!

In hw1.rb we defined a function called blockin_time that requires the foobar.rb file, and then calls a class method 'baz' from the Foobar class.

If you take a look at the foobar.rb, you'll see that we've defined Foobar. Write a class function in foobar.rb called baz that takes in an array of integers as strings, changes each string into an integer, adds two to each number, keeps the even numbers only, takes out any duplicates, rejects the resulting numbers greater than ten, and returns the sum of the resulting array.

For example:

["1", "2", "3", "4", "5", "10"] returns 10. ((2+2) + (4+2)) = 10.

["1", "2", "2", "2", "3", "4", "5", "10"] also returns 10.

Challenge

  • Q1-Q3 can be written in 1 line and under 40 characters. Q4 can be written in under 80 characters in q line if you exclude the def and end statement. Do this if you want an extra challenge.

  • Check out the autograder.rb file and try to figure out how it works!

Hints

irb hw1.rb

How to check your Answers

In the base directory of this repo run 'ruby autograder.rb'.

ruby autograder.rb

If 'All functions work' appears in your terminal it means it passed our autograder. We do go over

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.