Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Combine Lists
- // Write a program that reads two lists of numbers and combines them by alternatingly taking elements:
- // combine 1,2,3 and 7,8,9 -> 1,7,2,8,3,9
- // you can assume that the input lists will have the same length.
- // Print the resulting combined list to the output, separating elements with a comma.
- // Input
- // On the first line you will receive the first list.
- // On the second line -> 2nd list.
- // Output
- // On the only line of output, print all the numbers in format n1,n2,n3,..n
- // Input
- // 2,3,1
- // 5,2,3
- // Output
- // 2,5,3,2,1,3
- const input = ['2,3,1', '5,2,3'];
- const print = this.print || console.log;
- const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- const firstArr = gets().split(',');
- const secondArr = gets().split(',');
- const combinedArr = [];
- for (let i = 0; i < firstArr.length; i++) {
- combinedArr.push(firstArr[i]);
- combinedArr.push(secondArr[i]);
- }
- print(combinedArr.join(','));
Advertisement
Add Comment
Please, Sign In to add comment