-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnomor7.js
More file actions
24 lines (21 loc) · 774 Bytes
/
nomor7.js
File metadata and controls
24 lines (21 loc) · 774 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
const array1 = ["Mangga","Apel","Melon","Pisang","Sirsak","Tomat","Nanas","Nangka","Timun","Mangga"];
const array2 = ["Bayam","Wortel","Kangkung","Mangga","Tomat","Kembang Kol","Nangka","Timun"];
function compareArrays(arr1,arr2){
let sameValue=[];
let differentValue=[];
for(let i=0;i<arr1.length;i++){
if(arr2.includes(arr1[i]) && !sameValue.includes(arr1[i])){
sameValue.push(arr1[i]);
}
else if(!arr2.includes(arr1[i])){
differentValue.push(arr1[i]);
}
}
for(let i=0;i<arr2.length;i++){
if(!arr1.includes(arr2[i])){
differentValue.push(arr2[i]);
}
}
return `Same : ${sameValue}\nDifferent : ${differentValue}`;
}
console.log(compareArrays(array1,array2));