This function checks if two arrays are identical (considering order). It converts the arrays to JSON strings for comparison.
JavaScript:
let areArraysEqual = (arr1, arr2) => JSON.stringify(arr1) === JSON.stringify(arr2);
// Example
console.log(areArraysEqual([1, 2, 3], [1, 2, 3])); // true
console.log(areArraysEqual([1, 2, 3], [3, 2, 1])); // false
TypeScript:
let areArraysEqual = (arr1: Array<any>, arr2: Array<any>): boolean => JSON.stringify(arr1) === JSON.stringify(arr2);
// Example
console.log(areArraysEqual([1, 2, 3], [1, 2, 3])); // true
console.log(areArraysEqual([1, 2, 3], [3, 2, 1])); // false