0

Values is list of obervables over input fields

    var example = combineLatest(values);

How do I find sum of values in text field.

    example.subscribe(val => {
        console.log('Sum:', val);
    });

Having subscriber over it gives me output of the form

Sum: (2) ["1", "2"]

Piping over combineLatest gives me NaN

     .pipe(reduce((acc, one) => {
         var a =Number(acc) + Number(one);
         console.log(a);
         return a;
     }, 0));
Delfin
  • 607
  • 7
  • 18

1 Answers1

3

You don't have to reduce the Observable, you have to reduce the array it emits.

var example = combineLatest(values).pipe(
  map(array => array.reduce((pv, cv) => pv + Number(cv), 0))
);
frido
  • 13,065
  • 5
  • 42
  • 56