Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let input = [[4,1,2 ],[1, 3, 4, 2],];
- let print = this.print || console.log;
- let gets =
- this.gets ||
- (
- (arr, index) => () =>
- arr[index++]
- )(input, 0);
- let firstArray = gets().split(',');
- let secondArray = gets().split(',');
- let newArray = [];
- for (let i = 0; i < firstArray.length; i++) {
- for (let j = 0; j < secondArray.length; j++) {
- if (firstArray[i] === secondArray[j]) {
- if (isNaN(secondArray[j + 1])) {
- newArray.push(-1);
- break;
- } else {
- for (let x = j + 1; x < secondArray.length; x++) {
- if (secondArray[x] > firstArray[i]) {
- newArray.push(secondArray[x]);
- break;
- } else {
- if (x + 1 === secondArray.length) {
- newArray.push(-1);
- break;
- }
- }
- }
- }
- }
- }
- }
- console.log(newArray.join(","));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement