Advertisement
elena1234

How to work with filter - JavaScript

Aug 19th, 2021
1,822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function extract(array) {
  2.     let max = Number.MIN_SAFE_INTEGER;
  3.     let newArray = array.filter(number => {
  4.         if (number > max) {
  5.             max = number;
  6.             return true;
  7.         } else {
  8.             return false;
  9.         }
  10.     });
  11.  
  12.     console.log(newArray);
  13. }
  14.  
  15. extract([1,
  16.     3,
  17.     8,
  18.     4,
  19.     10,
  20.     12,
  21.     3,
  22.     2,
  23.     24]    
  24.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement