equalizeArray

    0

    0

    The equalizeArray() function takes an array of objects as input, and reduces it down to an Array of numbers. The Array of numbers is then sorted so that the numbers in the array are all greater than the number at the bottom of the list, and the array length is reduced by the number of items in the list.

    function equalizeArray(arr) {
      let max = 0;
      let values = arr.reduce((target, value, index) => {
        target[value] = (target[value] || 0) + 1;
    
        target[value] > max && (max = target[value]);
    
        return target;
      }, []);
    
      return arr.length - max;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.