Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

count number of duplicate pairs in array javascript

// how to count number of duplicate pairs in array javascript
function countNumberOfPairs(arr) {
    let pairsCount = 0;
    let counterObj = {};

  for (let num of arr) {
    if (!counterObj[num]) {
      counterObj[num] = 1;
    } else {
      counterObj[num] = counterObj[num] + 1;

      if (counterObj[num] === 2) {
        pairsCount++;
        counterObj[num] = 0;
      }
    }
  }
  return pairsCount;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Codewars JS Multiples of 3 or 5 
Javascript :: jquery select option by text 
Javascript :: get placeholder innertext 
Javascript :: javascript get element tag 
Javascript :: load base64 image in tab javascript 
Javascript :: hwo to cehck req header in js 
Javascript :: discordjs eval 
Javascript :: js ceil 
Javascript :: how to fix Composer could not find a composer.json file in Z:xampp 7312htdocsproject_karakter-master 
Javascript :: node get absolute path 
Javascript :: get keys of object in an array 
Javascript :: react import css only for component 
Javascript :: nice react native shadow 
Javascript :: spread operator merge objects 
Javascript :: react bind function to component 
Javascript :: redux dev tools 
Javascript :: regex not contain 
Javascript :: Warning: Prop `className` did not match. Client and server rendered different classes . 
Javascript :: how to reload the window by click on button in javascript 
Javascript :: check date in between two dates nodejs 
Javascript :: Jquery handle change event of file upload created dynamically 
Javascript :: fill an array of zeroes in js 
Javascript :: call laravel route js 
Javascript :: append HTML elements in JavaScript 
Javascript :: get full month from date javascript 
Javascript :: javascript ajax load html into div 
Javascript :: Uncaught TypeError: $(...).DataTable is not a function 
Javascript :: javascript operator double pipes 
Javascript :: find object in array javascript with property 
Javascript :: props vue 3 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =