Javascript with regex
function getData(rfd) { let lines = rfd.split('\n'); let cmap = new Map(lines.map(l => { let parts = l.split(':'); return [parts[0], parts[1].split(/[^0-9.]+/) .filter(v => v.length > 0) .map(v => parseFloat(v))] })); return cmap; } function mean(country, rainfalldata) { let d = getData(rainfalldata).get(country); if(!d) { return -1; } return d.reduce((acc, v) => acc + v, 0) / d.length; } function variance(country, rainfalldata) { let m = mean(country, rainfalldata); if(m === -1) { return -1; } let d = getData(rainfalldata).get(country); return d.map(v => (v - m) * (v - m)).reduce((acc, v) => acc + v, 0) / (d.length) }
Fyi, you can add language specific syntax styling immediately after the first code back-ticks.
github.com/adam-p/markdown-here/wi...
Thanks, Matt. I tried that, and if you see my other posts you'll see I was successful, but it's not working for this one for some reason
Ah! I hadn't closed the three back ticks!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Javascript with regex
Fyi, you can add language specific syntax styling immediately after the first code back-ticks.
github.com/adam-p/markdown-here/wi...
Thanks, Matt. I tried that, and if you see my other posts you'll see I was successful, but it's not working for this one for some reason
Ah! I hadn't closed the three back ticks!