JenMorgan / js-learning

0 stars 0 forks source link

Write a JavaScript function to merge two arrays and removes all duplicates elements #33

Open kartamyshev opened 4 years ago

kartamyshev commented 4 years ago
const array1 = [1, 2, 3];
const array2 = [2, 30, 1];
mergeUniq(array1, array2); // [3, 2, 30, 1]
JenMorgan commented 4 years ago
function mergeUniq (arr1, arr2) {
    const concattedArray = arr1.slice();
    for (const item of arr2) {
        if (!arr1.includes(item)) concattedArray.push(item);
    }
    return concattedArray;
}