Answer to Question #303240 in HTML/JavaScript Web Application for king

Question #303240

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 */

}


1
Expert's answer
2022-03-03T07:26:03-0500
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)
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS