Advertisement
AreWe

Non-Decreasing Subsequence nikolay

Jan 23rd, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. function solve(arr){
  2.  
  3. const newArr = []
  4. let prevNum = arr[0]
  5. newArr.push(prevNum)
  6.  
  7. for(let i = 1; i < arr.length; i++){
  8.  
  9. currentNum = arr[i]
  10.  
  11. if(currentNum >= prevNum){
  12. newArr.push(currentNum)
  13. prevNum = currentNum
  14. }
  15. }
  16. console.log(newArr.join(` `));
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement