Coder Social home page Coder Social logo

fa17-hw1's Introduction

Rails DeCal Fall 2017 Homework 1

This assignment involves writing scripts in Ruby to help you become familiar with the Ruby programming language.

Q1

There is a method called squared_sum in hw1.rb. squared_sum accepts two integer parameters a and b. The method should calculate the sum of a and b and then return the square of the sum. Please finish this method.

Q2

There is a method called sort_array_plus_one in hw1.rb. sort_array_plus_one accepts an array of integers as its parameter. The method should sort the given array, increment each element by 1, and finally return it. Please finish this method, either in a destructive or non-destructive fashion.

Q3

There is a method called combine_name in hw1.rb. combine_name accepts two string parameters first_name and last_name. The method should return the first_name concatenated with the last_name with a space in between. Please finish this method.

Example:

combine_name 'Jon', 'Chu'
 => 'Jon Chu'

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 foobar.rb, you'll see that we've defined Foobar. Write a class function in foobar.rb called baz that accepts an array of integers as strings, changes each string into an integer, adds two to each number, keeps the even numbers only, removes any duplicates, rejects the resulting numbers greater than ten, and finally returns the sum of the resultingarray.

For example:

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

['1', '2', '2', '2', '3', '4', '5', '10'] returns 10 as well.

Challenges

  • Q1-Q3 can be written in 1 line and under 40 characters. Do this if you want an extra challenge.

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

Hints

  • For Q2 check out these docs about arrays. In web development in general, there are a lot of docs available when learning new libraries.

  • For Q3 you might want to check out [Ruby's string interpolation] (https://en.wikipedia.org/wiki/String_interpolation#Ruby).

  • To open the ruby interpreter to help debug call the 'irb' command in your terminal with the hw1.rb file.

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, everything is correct!

fa17-hw1's People

Contributors

garrettwesley avatar jonmchu avatar warrenshen avatar

Watchers

James Cloos 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.