Counting Frequency

let data1 = 'This is a fairly short string.'
let data2 = [ 1,2,3,4,2,4,2,3,4,5,2,5,1,3 ]
function dataToFrequency(data){
let frequency = {}
for(let i = 0; i < data.length; i++){
frequency[data[i]]
? frequency[data[i]] += 1
: frequency[data[i]] = 1
}
return frequency
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store