Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
underscore.countBy solution in Clear category for [old] The Most Frequent by kurosawa4434
"use strict";
const _ = require('underscore');
function mostFrequent(data) {
const cb_data = _.countBy(data);
return _.keys(cb_data).reduce((a, b)=>cb_data[a] > cb_data[b] ? a: b);
}
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. 1, 2018