Advertisement
CLooker

Untitled

Feb 2nd, 2018
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // https://www.hackerrank.com/challenges/equality-in-a-array/problem
  2.  
  3. function equalizeArray(arr) {
  4.     let coll = [];
  5.     for (let i = 0; i < arr.length; i++) {
  6.         const target = arr[i];
  7.         let tempColl = [target];
  8.         for (let j = 0; j < arr.length; j++) {
  9.             if (j != i) {
  10.                 if (arr[j] === target) {
  11.                     tempColl.push(arr[j])
  12.                 }
  13.                 coll.push(tempColl)
  14.             }
  15.         }
  16.     }
  17.     let biggestTempColl = 0;
  18.     coll.forEach(tempColl => {
  19.         if (tempColl.length > biggestTempColl) {
  20.             biggestTempColl = tempColl.length;
  21.         }
  22.     })
  23.     return arr.length - biggestTempColl;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement