這是爲了理解函數式編程。函數式編程示例
它來自一篇關於嫌雜誌: 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