Skip to content

learn-co-students/pfwtfp-practice-with-array-integers-lab-dc-web-mod1-repeat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Practice with Array Integers

Introduction

In this lab, we will be practicing some of the common ways to access and manipulate information from an array.

Learning Goals

  • Access values in arrays
  • Perform operations on arrays

Perform Operations on Arrays

This lab focuses on arrays of integers but involves a few concepts from algebra. Just as a brief refresher on some of these concepts:

To square a number, multiple the number by itself. In mathematical notation, this is written using a exponent: 52 == 5 x 5 == 25

To cube a number, multiple a number by itself two times. 53 == 5 x 5 x 5 == 125

To sum a set of numbers, add them together

To average a set of numbers, get their sum and divide by how many numbers are in the set

Your task is to write a set of methods that take in an any array of integers, perform a math operation on each integer and return a new array. In lib/array_practice.rb, an example array is provided:

array_of_integers = *0..50
# => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9,  ...  47, 48, 49]

This method of array creation uses a 'splat' operator on a range. This is a shorthand method for creating and assigning an array of integers

Feel free to modify this array or use your own array to test and write these methods. Comments are provided in lib/array_practice.rb for each method you will need to write. Run learn to test your solutions.

Conclusion

There are many ways to manipulate arrays of integers. These operations are common enough that some of the methods you've written are actually built into Ruby as class methods. Being able to access and modify array data

Resources

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages