Advertisement
Guest User

Untitled

a guest
Oct 4th, 2023
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. let input = [[4,1,2 ],[1, 3, 4, 2],];
  2.  
  3. let print = this.print || console.log;
  4. let gets =
  5. this.gets ||
  6. (
  7. (arr, index) => () =>
  8. arr[index++]
  9. )(input, 0);
  10.  
  11. let firstArray = gets().split(',');
  12. let secondArray = gets().split(',');
  13. let newArray = [];
  14.  
  15. for (let i = 0; i < firstArray.length; i++) {
  16. for (let j = 0; j < secondArray.length; j++) {
  17.  
  18. if (firstArray[i] === secondArray[j]) {
  19.  
  20. if (isNaN(secondArray[j + 1])) {
  21. newArray.push(-1);
  22. break;
  23. } else {
  24.  
  25. for (let x = j + 1; x < secondArray.length; x++) {
  26.  
  27. if (secondArray[x] > firstArray[i]) {
  28. newArray.push(secondArray[x]);
  29. break;
  30. } else {
  31.  
  32. if (x + 1 === secondArray.length) {
  33. newArray.push(-1);
  34. break;
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }
  42.  
  43. console.log(newArray.join(","));
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement