Git Product home page Git Product logo

programming-univbasics-4-square-array-test-development's Introduction

Square Array

Learning Goals

  • Apply while to iterate over an array

Introduction

In this lab we will be building a method, square_array, that squares each element in an array of numbers and returns a new array of these squared numbers.

Hint: There is more than one way to square numbers! Google Ruby's exponent operator or refer back to the earlier lesson on simple math.

Apply while to Iterate Over an Array

To build this method, use the iterator while and implement your own logic. Use only while, Arrays, and any other previously discussed methods for the solution. Don't use the Ruby docs or the internet to find built-in methods or code you may not understand yet.

Example:

numbers = [1,2,3]

square_array(numbers)
# => [1,4,9])

new_numbers = [9,10,16,25]

square_array(new_numbers)
# => [81,100,256,625]

Once you have the tests passing, you can optionally test out implementing this with a higher level iterator.

Conclusion

As demonstrated, Ruby gives us a number of shortcuts to complete iterative tasks with ease. Instead of manually writing loops, you can achieve the same results with fewer lines of code.

Resources

programming-univbasics-4-square-array-test-development's People

Watchers

 avatar Mohawk Greene avatar Victoria Thevenot avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar  avatar  avatar Ben Oren avatar Matt avatar Antoin avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Dominique De León avatar Kaeland Chatman avatar  avatar Lisa Jiang avatar Vicki Aubin avatar Maxwell Benton avatar  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.