Advertisement
bai_onzi

aloneNumbers

Mar 1st, 2023
69
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. let result = [];
  5.  
  6. for(let i = 0; i < arr.length; 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.     }
  16.    
  17. }
  18. console.log(result.join());
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement