Compares two arrays and output to the console an error message if arrays is not identical.
- Copyright:
- 2011 Data Arts Team, Google Creative Lab
- License:
- under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- Source:
Methods
(inner) compareArrays(a1, a2opt)
Compares two arrays and output to the console an error message if arrays is not identical.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a1 |
Array | Object | if type is Array then, this array will be compare with a2 Example. The following code: const a1 = [1, 2, 3, 'cat' , [1.1, 1.1000000001], { name: 'Tom' , age: 20 }]; const a2 = [1, 2, 4, 'mouse', [1.2, 1.1000000002], { name: 'Jerry', age: 20 }]; a1.i = 5; compareArrays(a1, a2); will output to the console: compareArrays: trueArray[2]: 3 !== checkArray[2]: 4 compareArrays: trueArray[3]: cat !== checkArray[3]: mouse compareArrays: trueArray[4]["0"]: 1.1 !== checkArray[4]["0"]: 1.2 compareArrays: trueArray[5]["name"]: Tom !== checkArray[5]["name"]: Jerry compareArrays: checkArray["i"] is undefined. Note: a1[4]["1"] = 1.1000000001 is equal a2[4]["1"] = 1.1000000002 because the difference between two floats is less than 1.2e-5. if type is Object then an object with two keys: First key is true array. Second key is array to check. Example. The following code: const a1 = [1, 2, 3, 'cat' , [1.1, 1.1000000001], { name: 'Tom' , age: 20 }]; const a2 = [1, 2, 4, 'mouse', [1.2, 1.1000000002], { name: 'Jerry', age: 20 }]; a1.i = 5; compareArrays({a1: a1, a2: a2}); will output to the console: compareArrays: a1[2]: 3 !== a2[2]: 4 compareArrays: a1[3]: cat !== a2[3]: mouse compareArrays: a1[4]["0"]: 1.1 !== a2[4]["0"]: 1.2 compareArrays: a1[5]["name"]: Tom !== a2[5]["name"]: Jerry compareArrays: a2["i"] is undefined. |
|
a2 |
Array |
<optional> |
This array will be compare with a1. Use only if a1 is Array type |
- Source: