Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="// http://stackoverflow.com/questions/1053843">
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
// most libs will include a similar utility
if(!Object.values) Object.values = function(ob){
    var arr = [];
    for(var k in ob) 
        if(ob.hasOwnProperty(k))
            arr.push(ob[k]);
    return arr;
};
function multiMode(arr){
    var map = arr.reduce(function(map, item){
        if(!(item in map)) map[item] = 0;
        return map[item]++, map;
    }, {});
    var max = Math.max.apply(null, Object.values(map)),
        arr2 = [];
    Object.keys(map).forEach(function(k){
        if(map[k] === max) arr2.push(k);  
    });
    return arr2;
}
console.log(multiMode(['pear', 'apple', 'orange', 'apple', 'pear', 'pear', 'apple']));
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
Digigizmopro
0viewers