Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function extract(arr) {
- let currentEl = Number.NEGATIVE_INFINITY;
- let outputArr = arr.reduce((acc, el) => {
- if (el >= currentEl) {
- currentEl = el;
- acc.push(el);
- }
- return acc;
- }, []);
- return outputArr;
- }
Advertisement
Add Comment
Please, Sign In to add comment