georgiev955

task 5

Sep 18th, 2023
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. function extract(arr) {
  2. let currentEl = Number.NEGATIVE_INFINITY;
  3.  
  4. let outputArr = arr.reduce((acc, el) => {
  5. if (el >= currentEl) {
  6. currentEl = el;
  7. acc.push(el);
  8. }
  9.  
  10. return acc;
  11. }, []);
  12.  
  13. return outputArr;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment