Answers for "how to find dublicates in string"

0

how to find dublicates in string

const names = ['Mike', 'Matt', 'Nancy', 'Adam', 'Jenny', 'Nancy', 'Carl'];

const count = names =>
  names.reduce((a, b) => {
    a[b] = (a[b] || 0) + 1;
    return a;
  }, {}); // don't forget to initialize the accumulator
const duplicates = dict => Object.keys(dict).filter(a => dict[a] > 1);

console.log(count(names)); // { Mike: 1, Matt: 1, Nancy: 2, Adam: 1, Jenny: 1, Carl: 1 }
console.log(duplicates(count(names))); // [ 'Nancy' ]
Posted by: Guest on May-17-2021

Code answers related to "how to find dublicates in string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language