Advertisement
bai_onzi

GreaterNumber mock4

Mar 6th, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let firstArray = gets().split(',').map(Number);
  2. let secondArray = gets().split(',').map(Number);
  3.  
  4. let resArr = [];
  5. for(let i = 0; i < firstArray.length; i++){
  6.     let index = secondArray.indexOf(firstArray[i]);
  7.     let result = -1;
  8.     for(let j = index + 1; j < secondArray.length;j++){
  9.         if(secondArray[j] > firstArray[i]){
  10.             result = secondArray[j];
  11.             break;
  12.         }
  13.     }
  14.     resArr.push(result);
  15. }
  16. console.log(resArr.join(','));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement