shamsmosowi / git-bot

0 stars 0 forks source link

merging duplicates #10

Open shamsmosowi opened 1 year ago

shamsmosowi commented 1 year ago

Hi,

If you are looking to merge duplicates in an array, you can use the JavaScript Array.prototype.reduce() method to do so. The reduce() method takes in a function as an argument which is used to combine the values of the array into a single value.

You can use the following code:

let mergedArray = arr.reduce((acc, curr) => {
  if (acc.includes(curr)) {
    return acc;
  } else {
    acc.push(curr);
    return acc;
  }
}, []);

The mergedArray will contain the values of the original array without the duplicates.

I hope this helps!