【发布时间】:2021-07-02 13:36:40
【问题描述】:
我目前正在使用一个函数来根据小数据集中的最大值分配自定义标签。数据集如下:
const team = [
{ name: 'John Doe', maxScore: '2', finishes: ['105', '108'] },
{ name: 'Peter Pie', maxScore: '1', finishes: ['140'] }
]
我想为 maxScore 值最高的玩家分配一个 Tag (antd)。我为此使用了以下代码:
const highestMaxScore = Math.max.apply(
Math,
team.map(function (t) {
return t.maxScore
})
)
这很好,但现在我想对饰面做同样的事情。主要问题,值列在数组中。我想不出修改之前使用的代码来得到我想要的结果。
感谢您的帮助!
【问题讨论】:
-
maxScore 和finish 值真的是字符串吗?不是数字吗?
-
当有多个值时,作业不明确。请提供输入和预期输出的示例,尤其是当
finishes具有低值和高值时。 -
我可以将字符串转换为数字,没关系,因为我不会使用这些值来计算东西或类似的东西
标签: javascript arrays reactjs object nested