Advertisement
dabidabidesh

Untitled

Jun 16th, 2020
2,467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function nonDecreasingSubsequence0(arr) {
  2.   console.log(arr.filter((el, index) => el >= Math.max(...arr.slice(0, index))).join(' '))
  3. }
  4.  
  5. nonDecreasingSubsequence1 = arr => {
  6.   'use strict'
  7.  
  8.   let max = arr[0]
  9.   let result = arr.filter(el => {
  10.     if (el >= max) max = el
  11.  
  12.     return el >= max
  13.   })
  14.  
  15.   console.log(result.join(' '))
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement