Git Product home page Git Product logo

sorted_array_with_iterators's Introduction

Iterators Lab

This lab builds on an implementation of SortedArray. A SortedArray is an array that always maintains the sorted order of its elements. Here is some example use of SortedArray:

arr = SortedArray.new([9,11,23,4,5,6,-10])
puts "All items:"
while i < arr.length
  puts arr[i]
  i += 1
end

arr.add(8)
puts "\nThe element at index 4 is now 8:"
puts arr[4]

Below is the output of the code:

All items:
-10
4
5
6
9
11
23

The element at index 4 is now 8:
8

NOTICE that the array is printed in sorted order. Since our SortedArray class always maintains order.

Objective

The objective is to implement the iterator methods in the sorted array class so that the tests pass. You will implement the following methods:

each
each_with_index
map
map!
find
inject  # BONUS!

Suggestions

  • Implement the methods in the order they are defined in the file.
  • Implement the each method first, then use the each method to implement other methods.
  • You should not have to write any while loops after you have written one in each.
  • Get very familiar with the iterator methods before you implement them. Use the ruby docs or use the methods in pry with a standard array.

Bonus

Implement SortedArray#inject. See if you can get it to work exactly like Array#inject.

sorted_array_with_iterators's People

Contributors

zealoushacker avatar tigarcia avatar

Watchers

 avatar James Cloos avatar Jacqueline Herrlin avatar Spencer Eldred avatar Delmer avatar Colt Steele 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.