Advertisement
bai_onzi

aloneNumbers MOCK 3

Mar 3rd, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let arr = gets().split(', ').map(Number);
  2. // console.log(arr)
  3. let target = +gets();
  4.  
  5.  
  6. for(let i = 1; i < arr.length - 1; i++){
  7.     let currentN = arr[i];
  8.     let prevN = arr[i - 1];
  9.     let nextN = arr[i + 1];
  10.     if(currentN === target){
  11.         if(currentN !== prevN && currentN !== nextN){
  12.             currentN = Math.max(prevN, nextN)
  13.         }
  14.         // result.push(prevN, currentN, nextN)
  15.         arr[i] = currentN;
  16.     }
  17.    
  18. }
  19. console.log(`[${arr.join(', ')}]`);
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement