To show how powerful the flatMap() operator can be we can create a function to emulate the filter() operator using only the flatMap() operator; this function must have the following signature:
It will receive two parameters and both are mandatory:
- observable: It is the observable to filter data
- filter: It is a function that chooses if an element should be filtered or not
And it must return an observable for the filter.
Before coding our function, let's create a test suite to test it.
Let's use mocha as we learned in the previous chapter. We can define our test group using the describe() function:
var assert = require('assert'); ...