-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
29 lines (27 loc) · 962 Bytes
/
Copy pathutils.js
File metadata and controls
29 lines (27 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Returns `true` in case if array `A` has exactly the same elements list and elements order as array `B`
* @param {[]} a Array `A`
* @param {[]} b Array `B`
* @returns {boolean}
*/
var sameArrays = function (a, b) {
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
return true;
};
/**
* Returns `true` in case if array `A` has exactly the same subarrays list as array `B` (subarray orders is not considered)
* @param {[]} a Array `A`
* @param {[]} b Array `B`
* @returns {boolean}
*/
var sameSubArrays = function (a, b) {
if (a.length !== b.length) return false;
//check if all subarrays of A can be found in B
for (let i = 0; i < a.length; i++)
if (!b.find((e) => sameArrays(e, a[i]))) return false;
//check if all subarrays of B can be found in A
for (let i = 0; i < b.length; i++)
if (!a.find((e) => sameArrays(e, b[i]))) return false;
return true;
};
module.exports = { sameArrays, sameSubArrays };