-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2-pipe.js
More file actions
34 lines (26 loc) · 707 Bytes
/
2-pipe.js
File metadata and controls
34 lines (26 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const { Observable } = require('rxjs');
const { filter, map } = require('rxjs/operators');
const randomChar = () => String
.fromCharCode(Math.floor((Math.random() * 25) + 97));
const source = new Observable((subscriber) => {
setInterval(() => {
const char = randomChar();
subscriber.next(char);
}, 200);
});
const destination = source.pipe(
filter((char) => !'aeiou'.includes(char)),
map((char) => char.toUpperCase())
);
let count = 0;
const observer = (char) => {
process.stdout.write(char);
count++;
if (count > 50) {
process.stdout.write('\n');
process.exit(0);
}
};
destination.subscribe(observer);
console.dir({ observer, source, destination });