Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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' ]
Comment

PREVIOUS NEXT
Code Example
Javascript :: @webfilter objectify where we can use 
Javascript :: concat two arrays in react 
Javascript :: 1.047222170078745 
Javascript :: install react-foundation library in react js 
Javascript :: replace with regex capture group 
Javascript :: how to pass an id to the route of a seprate file react 
Javascript :: convert python to js online 
Javascript :: firestore return the content of an aarray Nodejs 
Javascript :: Diff is not a function in Moment.js 
Javascript :: how to insert keycode in switch statement in javascript 
Javascript :: js string vs number difference 
Javascript :: emit value from node server 
Javascript :: javascript accessing this in callback 
Javascript :: 4.7.1. The String Operator +¶ 
Javascript :: how to create a mixed array in javascript 
Javascript :: event pooling in react/event.persist/using async function in event callback 
Javascript :: 7.2. Bracket Notation¶ 
Javascript :: double and operator javascript 
Javascript :: facebook graph X-Hub-Signature 
Javascript :: How to update Code Mirror data on modal show 
Javascript :: check the constructor property to find out if an object is an Array (contains the word "Array"): 
Javascript :: jquery ui sortable disable child 
Javascript :: Using Scrip as Web app 
Javascript :: js match property 
Javascript :: Destructing variable assignment 
Javascript :: aurelia shadow dom 
Javascript :: mac address validation regex angular 
Javascript :: js get word before question mark 
Javascript :: stop interval javascript 
Javascript :: open screen pdf on google drive react native expo 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =