SHARE
TWEET

Untitled

a guest Oct 10th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arrStr, target){
  2.     let nums = arrStr.split(', ').map(Number);
  3.  
  4.     let currentIndex = -1
  5.     do{
  6.         currentIndex = nums.indexof(target);
  7.         if (currentIndex === -1) break;
  8.    
  9.         if(currentIndex === 0 || currentIndex === nums.length()-1) continue;
  10.    
  11.         if (nums[currentIndex-1!== target] && nums[currentIndex+1] !== target){
  12.             nums[currentIndex] = Math.max(nums[currentIndex-1], nums[currentIndex+1]);
  13.         }
  14.     } while(currentIndex !== -1)
  15.  
  16.     console.log(nums);
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top