Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function nonDescendingSubsequences(array){
- array = array.map(Number);
- let result = [array[0]];
- let biggestNum = [array[0]];
- for(let i = 1;i < array.length;i++){
- let currentNumber = array[i];
- if(currentNumber >= biggestNum){
- result.push(currentNumber);
- biggestNum = currentNumber;
- }
- }
- console.log(result.join(' '));
- }
- nonDescendingSubsequences([20,3,2,15,6,1]);
Advertisement
Add Comment
Please, Sign In to add comment