/**
* @param {number[]} arr
* @param {number[][]} pieces
* @return {boolean}
*/
var canFormArray = function (arr, pieces) {
const map = new Map(),
{ length } = arr;
for (const piece of pieces) {
map.set(piece[0], piece);
}
let i = 0;
while (i < length) {
if (!map.has(arr[i])) {
return false;
}
const compareArray = map.get(arr[i]);
let j = 0;
while (j < compareArray.length) {
if (arr[i] !== compareArray[j]) {
return false;
}
++i, ++j;
}
}
return true;
};