fune/testing/web-platform/tests/common/arrays.js
Simon Pieters ad0c1a7b06 Bug 1587010 [wpt PR 19565] - [docs] Add JSDoc comments in common/*.js files, a=testonly
Automatic update from web-platform-tests
[docs] Add JSDoc comments in common/*.js files (#19565)

Part of #17913.
--

wpt-commits: 99c68a16098df7ec4182aadc3795b579a77a161f
wpt-pr: 19565
2020-01-31 20:40:28 +00:00

31 lines
687 B
JavaScript

/**
* Callback for checking equality of c and d.
*
* @callback equalityCallback
* @param {*} c
* @param {*} d
* @returns {boolean}
*/
/**
* Returns true if the given arrays are equal. Optionally can pass an equality function.
* @param {Array} a
* @param {Array} b
* @param {equalityCallback} callbackFunction - defaults to `c === d`
* @returns {boolean}
*/
export function areArraysEqual(a, b, equalityFunction = (c, d) => { return c === d; }) {
try {
if (a.length !== b.length)
return false;
for (let i = 0; i < a.length; i++) {
if (!equalityFunction(a[i], b[i]))
return false;
}
} catch (ex) {
return false;
}
return true;
}