Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let arr = gets().split(', ').map(Number);
- // console.log(arr)
- let target = +gets();
- for(let i = 1; i < arr.length - 1; i++){
- let currentN = arr[i];
- let prevN = arr[i - 1];
- let nextN = arr[i + 1];
- if(currentN === target){
- if(currentN !== prevN && currentN !== nextN){
- currentN = Math.max(prevN, nextN)
- }
- // result.push(prevN, currentN, nextN)
- arr[i] = currentN;
- }
- }
- console.log(`[${arr.join(', ')}]`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement