Giter Site home page Giter Site logo

array-chapter's Introduction

Ruby Practice

Run your Ruby file by typing ruby and then the name of the file you want to run in the Terminal.

If we want to run array_count.rb, we can write the command:

ruby array_count.rb

To re-run this command, you can use the UP and DOWN arrow keys to look at the history of commands you've run in a Terminal.

Array

array_element_square.rb

Ask the user to enter at least 2 numbers. Store the user's input. The first few lines of code provided in the file does this for you.

Print the square of the second-to-last number that the user enters.

The expected output will be something like:

"Enter at least 2 numbers, separated by spaces:"
42 5 3 8 # user's input
9.0

array_count.rb

Ask the user to enter at least 2 numbers. Store the user's input. The first few lines of code provided in the file does this for you.

Use the count method to print how many numbers the user entered.

Expected output:

"Enter at least 2 numbers, separated by spaces:"
42 5 3 8 # user's input
4

array_reverse.rb

Ask the user to enter at least 2 numbers. Store the user's input. The first few lines of code provided in the file does this for you.

Use the reverse method to return the numbers in reverse order.

Expected output:

"Enter at least 2 values, separated by spaces:"
42 5 3 8 # user's input
[8, 3, 5, 42]

array_min_max_difference.rb

Use the provided array (don't ask the user for a value, in this task).

array = [12, 23, 41, 73, 19, 6]

Print the smallest number in the array, the largest number in the array, and the difference between the two.

array_sum_elements.rb

Use the provided array (don't ask the user for a value in this task).

Print the sum of the numbers in the provided array

Specs

Click here to see names of each test

array_count.rb should output '2' given the input '2 9'

array_count.rb should output '9' given the input '9 12 8 25 16 78 64 0 27'

array_count.rb should output '5' given the input '9 80 17 28 36'

array_element_square.rb should output '4.0' given the input '9 2 7'

array_element_square.rb should output '9.0' given the input '6 4 6 6 6 3 2'

array_element_square.rb should output '18.49' given the input '3.2 -1.1 -4.3 8.4'

array_min_max_difference.rb should output '6', '73', and '67' on separate lines

array_reverse.rb should output '['hello', 'zebra', '35', 'banana']' given the input 'banana 35 zebra hello'.

array_reverse.rb should output '[4, 3, 2, 1]' given the input '1 2 3 4'.

array_sum_elements.rb should output '151'

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.