'Is there any way to math min arrays inside array and return a array with the lowest numbers in each array? Javascript
Can't seem to wrap my head around this. Tried several solutions with for loops and math.min.
I have an array with arrays with numbers. I need to get the lowest number in each array.
Should look something like this.
let array = [[1, 2, 3],[85, 86, 87],[12, 13, 14],[8, 9, 10]]
let output = [[1],[85],[12],[8]]
Solution 1:[1]
You need to perform this operation on each value of the array => .map
let array = [[1, 2, 3],[85, 86, 87],[12, 13, 14],[8, 9, 10]]
const min = array.map( arr => Math.min(...arr))
// with the desired format: let output = [[1],[85],[12],[8]]
const output = array.map( arr => [Math.min(...arr)])
console.log(min)
console.log(output)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | malarres |
