In the iterators lab we will be continuing our exploration of iterators and building a few more useful methods. These methods will belong to an Iterators namespace, which we discussed in class. We also will try to use various testing methods to verify that our code is working.
Research the following term and summarize your findings on it two to three sentences:
higher-order function
Pretending we implemented the following methods, update this README with a description of each of the following and an example you've created:
max
: returns the highest number of a group. ex. Math.max(3,2,9) = 9min
: returns the lowest number of a group. ex. Math.min(3,2,9) = 2each
: runs a function on each array element. ex. array.forEach(function[])map
: creates a new array by running a function on each individual value within an arrayfilter
: creates a new smaller array of elements that fit stated criteria from the provided array notereduce
: combines all values in an array and returns a single number notereject
: returns an object if the provided reason matches the function's promise note
Use the notes provided to help guide you explanation.
-
Write a test in the
spec
folder formin
and implement it in thesrc/iterators.js
folder. There is a test for amax
method already if you'd like to use that as inspiration. -
Re-implement the
each
function, but write the spec for it first. Continue this exercise withmap
andfilter
and write tests first!
Implement the remaining iterator methods in the namespace and add tests for each one of them. Make sure that they return the correct data as well as datatype, and implement tests for edge cases (empty arrays, negative numbers).