We're a place where coders share, stay up-to-date and grow their careers.
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!
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!