Common arrays in three arrays
given three arrays arr1,arr2,arr3 write a JS program to find the common items in the among three arrays.
sample input1
[1,2,3,'cat']
[1,'cat',4]
[1,'cat,64]
output1
[1,'cat']
sample input2
['cat','rat','dog']
['lion','fox']
['kiwi','eagle']
output2
[]
function readLine() {
return inputString[currentLine++];
}
function main() {
let arr1 = JSON.parse(readLine().replace(/'/g, '"'));
let arr2 = JSON.parse(readLine().replace(/'/g, '"'));
let arr3 = JSON.parse(readLine().replace(/'/g, '"'));
/* Please do not modify anything above this line */
/* Write your code here */
}
function readLine() {
return inputString[currentLine++];
}
function main() {
let arr1 = JSON.parse(readLine().replace(/'/g, '"'));
let arr2 = JSON.parse(readLine().replace(/'/g, '"'));
let arr3 = JSON.parse(readLine().replace(/'/g, '"'));
/* Please do not modify anything above this line */
/* Write your code here */
let myArr = []
arr1.map(e => {
if (arr2.includes(e) && arr3.includes(e))
myArr.push(e)
})
console.log(myArr)
}
Comments
Leave a comment