ES6 判定兩個陣列是否相同
阿新 • • 發佈:2021-11-17
ES6 判定兩個陣列是否相同
1 private isEqual(arr1:number[], arr2:number[]): boolean{ 2 if(!arr1 || !arr2) { 3 return false; 4 } else { 5 if(arr1.length==0 && arr2.length==0){ 6 return true; 7 } else if(arr1.length==0 && arr2.length!=0 || arr1.length!=0 && arr2.length==0){ 8 return false; 9 } else { 10 let big: number[], small: number[]; 11 big = arr1.length>=arr2.length ? arr1: arr2; 12 small = big===arr1? arr2: arr1;13 for (let x = 0; x < big.length; x++) { 14 let b1 = big[x]; 15 if(small.indexOf(b1)==-1){ 16 return false; 17 } 18 } 19 return true; 20 } 21 }22 }