/**
* =====================================================
* In the index.html file, write the Arrayssimilar function to determine if the two incoming arrays are similar. Specific requirements:
* 1. The member types in the array are the same, and the order can be different. For example [1, True] is similar to [FALSE, 2].
* 2. The length of the array is consistent.
* 3. The type of judgment range that needs to be distinguished: String, Boolean, number, undefined, null, function, date, window.
*
* When all of the above are satisfied, then return "decision Result: Pass", otherwise return "decision Result: Do not pass".
* =====================================================
*/
/*
* param1 Array
* Param2 Array
* Return TRUE or False
*/
function Arrayssimilar (arr1, arr2) {
if (arr1 instanceof array && arr2 instanceof Array) {//First determine if an array is passed in
if (arr1.length = = arr2.length) {//determine array length
Console.log ("Same-length");
Console.log (ARR1);
Console.log (ARR2);
Start judging if the array is similar inside
Return Samelengtharrayssimilar (arr1, ARR2);
} else{
Two arrays of different lengths return False
return Console.log (FALSE);
}
} else {
The passed parameter is not an array return false
return false;
}
}
/**
* Determine if two equal-length arrays are similar inside
* Traversing arrays
* Whether the number of elements in the arr1 appears the same as the number of elements in the ARR2
* @param {array} arr1 arrays 1
* @param {array} arr2 arrays 2
* @return {True,false}
*/
function Samelengtharrayssimilar (ARR1,ARR2) {
var numInArr1 = 0;
var numInArr2 = 0;
var booleanInArr1 = 0;
var booleanInArr2 = 0;
var funInArr1 = 0;
var funInArr2 = 0;
var undefinedInArr1 = 0;
var undefinedInArr2 = 0;
var stringInArr1 = 0;
var stringInArr2 = 0;
var nullInArr1 = 0;
var nullInArr2 = 0;
var dateInArr1 = 0;
var dateInArr2 = 0;
var windowInArr1 = 0;
var windowInArr2 = 0;
Array Buer function undef str null data window
for (var i = 0; i < arr1.length; i++) {
if (typeof arr1[i] = = = ' number ') {
NUMINARR1 + +;
} else if (typeof arr1[i] = = = ' Boolean ') {
BOOLEANINARR1 + +;
} else if (typeof arr1[i] = = = ' function ') {
FUNINARR1 + +;
} else if (typeof arr1[i] = = = ' undefined ') {
UNDEFINEDINARR1 + +;
} else if (typeof arr1[i] = = = ' String ') {
STRINGINARR1 + +;
} else if (typeof arr1[i] = = = ' object ') {
if (Object.prototype.toString.apply (arr1[i]) = = = ' [Object Null] ') {
NULLINARR1 + +;
} else if (Object.prototype.toString.apply (arr1[i]) = = = ' [Object Date] ') {
DATEINARR1 + +;
} else if (Object.prototype.toString.apply (arr1[i]) = = = ' [Object global] ' {
WINDOWINARR1 + +;
}
}
if (typeof arr2[i] = = = ' number ') {
NUMINARR2 + +;
} else if (typeof arr2[i] = = = ' Boolean ') {
BOOLEANINARR2 + +;
} else if (typeof arr2[i] = = = ' function ') {
FUNINARR2 + +;
} else if (typeof arr2[i] = = = ' undefined ') {
UNDEFINEDINARR2 + +;
} else if (typeof arr2[i] = = = ' String ') {
STRINGINARR2 + +;
} else if (typeof arr2[i] = = = ' object ') {
if (Object.prototype.toString.apply (arr2[i]) = = = ' [Object Null] ') {
NULLINARR2 + +;
} else if (Object.prototype.toString.apply (arr2[i]) = = = ' [Object Date] ') {
DATEINARR2 + +;
} else if (Object.prototype.toString.apply (arr2[i]) = = = ' [Object global] ' {
WINDOWINARR2 + +;
}
}
}
if (numInArr1 = = numInArr2 && booleaninarr1==booleaninarr2 && funinarr1==funinarr2 && UNDEFINEDINARR1==UNDEFINEDINARR2 && stringinarr1==stringinarr2 && nullinarr1==nullinarr2 && DATEINARR1==DATEINARR2 && windowinarr1==windowinarr2) {
Console.log (' ================================true ');
return true;
}else{
Console.log (' ================================false ');
return false;
}
}
Determine if two arrays are similar