- Pairing
- Test driving
- Refactoring
A pair is working on the computer—working with a projector so the rest of the group can watch and kibitz.
There is a deck of features to implement:
- We only use one computer
- A pair starts off on the first feature
- We switch one member of the pair every 5 minutes
- Go back to step 3
You will need node
and npm
. Once you have those, run npm install
in the root directory and make sure running the tests works well by running the script run-tests
.
You might have to install mocha
globally so the mocha executable is on your path:
npm install -g mocha
- Write one test (in the
spec/f_spec.js
file) - Code to make that one test pass (in the
src/f.js
file) - Refactor to make it pretty
- Consider a commit
- Go back to #1
Run the script run-tests
to run the tests. The tests will run automatically as you save your js files.
We will implement our own version of the following list functions:
all
returns true if all elements of the array match the predicate
F.all([1,2,4,5], function(elem){return elem < 6;}) === true
any
returns true if at least one element of the array matches the predicate
F.any([1,2,4,5], function(elem){return elem > 5;}) === false
find
returns the first element of the array that matches the predicate or null
F.find([1,2,4,5], function(elem){return elem > 3;}) === 4
none
returns true if none of the elements of the array matches the predicate
F.none([1,2,4,5], function(elem){return elem > 6;}) === true
partition
returns an array of two arrays, the first one containing all elements of the array that match the predicate and the second array containing the rest
F.partition([1,2,4,5], function(elem){return elem > 2;}) → [[4,5], [1,2]]
group_by
returns a hash that groups the elements of the array (values) by the result of the predicate (keys)
F.group_by([1,2,4,5], function(elem){return elem % 2;}) → {1: [1,5], 0: [2,4]}
Extra points for grouping multiple arrays into one hash.
zip
accepts arrays as arguments and returns an array of arrays containing the first elements of each array in the first array, and then the second elements of each array, until the longest array is exhausted. Zips are padded with nulls.
F.zip([1,2,3], [4,5,6], [7,8,9,10]) → [[1,4,7], [2,5,8], [3,6,9], [null, null, 10]]
Zipping empty arrays should return an empty array.
See the rdoc for Enumerable for more complete specs.
As you implement the kata, pay attention to potential refactorings. Ask yourselves questions like:
- Did we cover all edge cases?
- What happens in our code when the arrays are empty?
- What happens in our code when the predicate returns
undefined
? - Are we going through the whole array when we don't have to?
- Can we get rid of old-style for loops?
- Can we implement one function in terms of another?
If you are curious about code coverage, you can generate a coverage report:
NODE_PATH=src grunt jasmine_node
The coverage report will be in coverage/lcov-report/index.html
.
Originally implemented @ JSLuxembourg.