Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
_.countBy solution in Clear category for [old] The Most Frequent by Sim0000
"use strict";
var _ = require('underscore')
function mostFrequent(data) {
let count = _.countBy(data)
return _.max(data, x => count[x])
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(mostFrequent([
'a', 'b', 'c',
'a', 'b',
'a'
]))
assert.equal(mostFrequent([
'a', 'b', 'c',
'a', 'b',
'a'
]), 'a')
assert.equal(mostFrequent(['a', 'a', 'bi', 'bi', 'bi']), 'bi')
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Feb. 5, 2018