Skip to content

Instantly share code, notes, and snippets.

@Woodsphreaker
Created August 16, 2017 22:18
Show Gist options
  • Save Woodsphreaker/68de51cb2e482e39702acc40286e7edc to your computer and use it in GitHub Desktop.
Save Woodsphreaker/68de51cb2e482e39702acc40286e7edc to your computer and use it in GitHub Desktop.
findMostRepeatValues
const groupSame = (acc, el) => {
acc[el]
? acc[el]++
: acc[el] = 1
return acc
}
const countDuplicate = (list) => list.reduce(groupSame, {})
const groupMostRepeat = (obj) => Object.keys(obj).reduce((a, b) => obj[a] > obj[b] ? a : b)
const findMostRepeat = (el) => groupMostRepeat(countDuplicate([...el]))
console.log(findMostRepeat('Aliquamineratdui.Maurispellentesqueleoatvelitfaucibustinciduntnonideros.')) // i
console.log(findMostRepeat('Lorempsumdolorstamet,consecteturadipiscingelit.')) // t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment