concatenate and remove Duplicates
Given two arrays arr1 and arr2 of positive integers write a JS program to concatenate two rows and remove duplicates from the concatenated array. Log the array with unique items in ascending order
input1
[1,4,7,3,7,3,3]
[2,4,5,5,3,2,1]
output1
[1,2,3,4,5,7]
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString
.trim()
.split("\n")
.map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
let arr1 = JSON.parse(readLine());
let arr2 = JSON.parse(readLine());
/* Please do not modify anything above this line */
/* Write your code here and log the output */
}
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString
.trim()
.split("\n")
.map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
let arr1 = JSON.parse(readLine());
let arr2 = JSON.parse(readLine());
/* Please do not modify anything above this line */
/* Write your code here and log the output */
const newArr = Array.from(new Set(arr1.concat(arr2))).sort()
console.log(newArr)
}
Comments
Leave a comment