Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

numeros que mais se repetem em um array

function getMostFrequent (arr) { 
   const hashmap = arr.reduce ((acc, val) => { 
    acc [val] = (acc [val] || 0) + 1 
    return acc 
}, {}) 
return Object.keys (hashmap ) .reduce ((a, b) => hashmap [a]> hashmap [b]? a: b) 
}
Source by javascript.plainenglish.io #
 
PREVIOUS NEXT
Tagged: #numeros #mais #se #repetem #em #um #array
ADD COMMENT
Topic
Name
2+5 =