From a80193a8ad9b0112f3a68bdf9e1b90470952999d Mon Sep 17 00:00:00 2001 From: Chandrashekhar Gouda Date: Wed, 11 Mar 2020 18:06:19 +0530 Subject: [PATCH] frequent element in an array --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0b4a10c..e95954e 100644 --- a/README.md +++ b/README.md @@ -473,6 +473,14 @@ el.addEventListener('click', myClickHandler, { }); ``` +# Most frequent element in an array. +```javascript +const mostFrequent = arr => + Object.entries( + arr.reduce((a, v) => { + a[v] = a[v] ? a[v] + 1 : 1; + return a; + }, {}) + ).reduce((a, v) => (v[1] >= a[1] ? v : a), [null, 0])[0]; - - +``` pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy