请让我知道如何解决这个问题。
let fifa =[
{
Winner: 'Uruguay',
Goals: 8,
Goalscorer: 'Guillermo Stábile',
Host: 'Uruguay',
Year: 1930
},
{
Winner: 'Italy',
Goals: 5,
Goalscorer: 'Oldřich Nejedlý',
Host: 'Italy',
Year: 1934
},
{
Winner: 'Italy',
Goals: 7,
Goalscorer: 'Leônidas',
Host: 'France',
Year: 1938
},
{
Winner: 'Uruguay',
Goals: 8,
Goalscorer: 'Ademir',
Host: 'Brazil',
Year: 1950
},
{
Winner: 'West Germany',
Goals: 11,
Goalscorer: 'Sándor Kocsis',
Host: 'Switzerland',
Year: 1954
},
{
Winner: 'Brazil',
Goals: 13,
Goalscorer: 'Just Fontaine',
Host: 'Sweden',
Year: 1958
},
];
let averageGoals = fifa.reduce(f => {
let sum = function(a,b){
return a+b;
}
return f.Goals(sum)/f.Goals.length;
}
);
提前谢谢你。
发布于 2020-10-26 17:30:37
调用函数的语法错误:
的每个步骤上计算
这里有一个可能的解决方案:
let fifa =[
{
Winner: 'Uruguay',
Goals: 8,
Goalscorer: 'Guillermo Stábile',
Host: 'Uruguay',
Year: 1930
},
{
Winner: 'Italy',
Goals: 5,
Goalscorer: 'Oldřich Nejedlý',
Host: 'Italy',
Year: 1934
},
{
Winner: 'Italy',
Goals: 7,
Goalscorer: 'Leônidas',
Host: 'France',
Year: 1938
},
{
Winner: 'Uruguay',
Goals: 8,
Goalscorer: 'Ademir',
Host: 'Brazil',
Year: 1950
},
{
Winner: 'West Germany',
Goals: 11,
Goalscorer: 'Sándor Kocsis',
Host: 'Switzerland',
Year: 1954
},
{
Winner: 'Brazil',
Goals: 13,
Goalscorer: 'Just Fontaine',
Host: 'Sweden',
Year: 1958
},
];
let averageGoals = fifa.reduce((tot, f) => {
return f.Goals + tot;
}, 0) / fifa.length;
console.log(averageGoals);
https://stackoverflow.com/questions/64534421
复制相似问题