JavaScript. How to Compare Input Arrays

后端 未结 6 1995
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 14:13

I\'m stuck with this problem for 3 days now... Someone please help me.

Challenge 5
Construct a function intersection

6条回答
  •  不知归路
    2021-01-15 14:30

    I think you want the common elements. Let me show you how:

    var Array1 = [5, 10, 15, 20]
    var Array2 = [15, 88, 1, 5, 7]
    var Array3 = [1, 10, 15, 5, 20]
    var found = []
    var Final = []
    var c = 1;e = 1;
    for (i = 1;i<=Array1.length;i++){
        for (k = 1;k<=Array2.length;i++){
            if (Array1[i] == Array2[k]){
                Found[c] = Array[i];
                c++;
            }
        }
    }
    for (n = 1;n <= Found.length ; n++){
        for (m = 1;m <= Array3.length ; n++){
            if (Found[n] == Array3[m]){
                Final[e] = Found[n]
                e++; 
            }
        }
    }
    //the Array Final Contains 5 , 15
    

提交回复
热议问题