-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp1.js
30 lines (20 loc) · 788 Bytes
/
app1.js
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
//Functional Way of Coding
var arr = ['2', '3', 'sdsd', '3', 'error', '6'];
var result = arr.map(x => parseInt(x))
.filter(x => !isNaN(x))
.reduce((t, x) => t + x);
console.log(result);
//Reactive Tutorial
//Create the source, which iterates through the item every 400 ms
var source = Rx.Observable.interval(400).take(arr.length)
.map(i => arr[i]);
//Map & Reduce the source to get the sum of all the integer element of the array
var reactiveSource = source.map(x => parseInt(x))
.filter(x => !(isNaN(x)))
.reduce((r, x) => r + x);
//Subscribe to final reactiveSource
reactiveSource.subscribe({
onNext: x => console.log(x),
onError: ex => console.log('Error Log:' + ex.message),
onCompleted: () => console.log('Completed !!')
});