Stack Overflow на русском Asked on December 28, 2021
let data = [
[
[],
[{'delta': 4.58}],
[{'delta': 3.17}]
],
[
[{'delta': 9.58}],
[{'delta': 7.21}],
[{'delta': 1.17}]
],
[
[{'delta': 11.51}],
[],
[{'delta': 3.08}]
]
];
console.log(data);
let min = 0; // ?
let max = 0; // ?
Твоя функция "не прокатывает" потому что элементами массива являются массивы, а не объекты с нужными полями.
В качестве решения можно воспользоваться методом flat
приводящим массив к одному уровню и лишь затем методом map получать значения нужных полей
let data = [
[
[],
[{
'delta': 4.58
}],
[{
'delta': 3.17
}]
],
[
[{
'delta': 9.58
}],
[{
'delta': 7.21
}],
[{
'delta': 1.17
}]
],
[
[{
'delta': 11.51
}],
[],
[{
'delta': 3.08
}]
]
];
console.log(Math.max(...data.flat(2).map(el => el.delta)))
Answered by Grundy on December 28, 2021
let data = [
[
[],
[{'delta': 4.58}],
[{'delta': 3.17}]
],
[
[{'delta': 9.58}],
[{'delta': 7.21}],
[{'delta': 1.17}]
],
[
[{'delta': 11.51}],
[],
[{'delta': 3.08}]
]
];
const newData = data.flat(Infinity);
console.log('max', newData.reduce((prev, current) => (prev.delta > current.delta) ? prev : current))
console.log('min', newData.reduce((prev, current) => (prev.delta > current.delta) ? current : prev))
Answered by meine on December 28, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP