Skip to content

Commit 1d747a9

Browse files
committed
Added array equal program
1 parent 7e5c2f0 commit 1d747a9

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

arrayEqual.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* -------------------------------------------------------
3+
* Programming Question : Arrays are Equal or not?
4+
* -------------------------------------------------------
5+
**/
6+
7+
8+
// 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.
9+
10+
//constraint
11+
//?
12+
//?
13+
//?
14+
//?
15+
16+
17+
function arraysAreEqual(arr1,arr2) {
18+
//if else
19+
if(arr1.length !== arr2.length ){
20+
return false;
21+
}
22+
return arr1.toString()===arr2.toString()
23+
24+
// every
25+
return arr1.every((curVal, index) => curVal === arr2[index])
26+
27+
}
28+
29+
console.log(arraysAreEqual([1,2,3],[1,2,3,2]));
30+
console.log(arraysAreEqual([1,2,3],[1,2,4]));
31+
console.log(arraysAreEqual([],[]));
32+

0 commit comments

Comments
 (0)