这是为了理解函数式编程。函数式编程示例
它来自一篇关于嫌杂志: http://www.smashingmagazine.com/2014/07/dont-be-scared-of-functional-programming/
嗨,我有以下数据
var data = [
{
name: "Jamestown",
population: 2047,
temperatures: [-34, 67, 101, 87]
},
{
name: "Awesome Town",
population: 3568,
temperatures: [-3, 4, 9, 12]
}
{
name: "Funky Town",
population: 1000000,
temperatures: [75, 75, 75, 75, 75]
}
];
我需要在一个新的数组
平均气温和平均人口和商店[
[average temperature, average population]
]
我想解决这个问题的方法是使用两个for循环。为什么这是解决问题的不好方法?为什么函数式编程是答案?
检查编辑 – Jasmine
该杂志不应该解释为什么他们认为函数式编程是“答案”吗? – crush