-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayEqual.js
More file actions
32 lines (23 loc) · 780 Bytes
/
arrayEqual.js
File metadata and controls
32 lines (23 loc) · 780 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
30
31
/**
* -------------------------------------------------------
* Programming Question : Arrays are Equal or not?
* -------------------------------------------------------
**/
// Q. Write a function arraysAreEqual that takes two arrays arr1 and arr2 as input returns true if the arryas are euqal (i.e, contain the same elemets in the same order), and false otherwise.
//constraint
//?
//?
//?
//?
function arraysAreEqual(arr1,arr2) {
//if else
if(arr1.length !== arr2.length ){
return false;
}
return arr1.toString()===arr2.toString()
// every
return arr1.every((curVal, index) => curVal === arr2[index])
}
console.log(arraysAreEqual([1,2,3],[1,2,3,2]));
console.log(arraysAreEqual([1,2,3],[1,2,4]));
console.log(arraysAreEqual([],[]));