-
Notifications
You must be signed in to change notification settings - Fork 1
/
MergeTwoArrays.js
27 lines (26 loc) · 763 Bytes
/
MergeTwoArrays.js
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
// program to merge and remove duplicate value from an array
function getUniqueAfterMerge(arr1, arr2){
let arr = [...arr1, ...arr2];
let uniqueArr = [...new Set(arr)];
console.log(uniqueArr);
}
const array1 = [1, 2, 3];
const array2 = [2, 3, 5]
// calling the function
getUniqueAfterMerge(array1, array2);
// program to merge and remove duplicate value from an array
function getUniqueAfterMerge(arr1, arr2){
let arr = arr1.concat(arr2);
let uniqueArr = [];
for(let i of arr) {
if(uniqueArr.indexOf(i) === -1) {
uniqueArr.push(i);
}
}
console.log(uniqueArr);
}
const array11 = [1, 2, 3];
const array22 = [2, 3, 5]
// calling the function
// passing array argument
getUniqueAfterMerge(array11, array22);