how to execution stop in typescript reduce() method

22 views
Skip to first unread message

Gopparunsolan Selvarasu

unread,
Jan 19, 2023, 2:06:34 PM1/19/23
to Angular and AngularJS discussion
Dear All,

I need reduce() method working in some condition not satistification the stop the execution.

Please Help me.

Below mentioned the Example code:

const array = ['apple', '-pen', '-pineapple', '-pen'];
    const x = array
      .slice(0) // create copy of "array" for iterating
      .reduce((acc, curr, i, arr) => {
        if (i === 1) 
           arr.splice(1); // eject early by mutating iterated copy
          console.log('i=> ', i);       
      }, '');

    

Gopparunsolan Selvarasu

unread,
Jan 19, 2023, 2:06:34 PM1/19/23
to Angular and AngularJS discussion
Dear All,

I am try to slice() method. but not stop execution. Below mentioned the code. kindly updates.

const x = array
      .slice(0) // create copy of "array" for iterating
      .reduce((acc, curr, i, arr) => {
        if (i === 1) arr.slice(1); // eject early by mutating iterated copy
Reply all
Reply to author
Forward
0 new messages