-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckTheBothArrayAreSameOrNot.js
More file actions
48 lines (38 loc) · 1022 Bytes
/
CheckTheBothArrayAreSameOrNot.js
File metadata and controls
48 lines (38 loc) · 1022 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Write a JavaScript program to find the number of elements in both arrays.
const prompt = require("prompt-sync")();
function isArrayEqual(arr1, arr2) {
var count = 0;
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] === arr2[i]) {
count++;
}
}
return count;
}
console.log("Enter Array-1 Size : ");
var size1 = parseInt(prompt());
var arr1 = [];
console.log("Enter Array-1 Elements : ");
for (let i = 0; i < size1; i++) {
console.log(`[${i}] : `);
var elem = parseInt(prompt());
arr1.push(elem);
}
console.log("\n");
console.log("Enter Array-2 Size : ");
var size2 = parseInt(prompt());
var arr2 = [];
console.log("Enter Array-2 Elements : ");
for (let i = 0; i < size2; i++) {
console.log(`[${i}] : `);
var elem = parseInt(prompt());
arr2.push(elem);
}
console.log("\n");
if (arr1.length === arr2.length) {
var equal = isArrayEqual(arr1, arr2);
console.log(equal);
} else {
console.log("Array Size cannot be same!");
console.log("We cannot match the elements!");
}