Skip to content

Instantly share code, notes, and snippets.

@mariohmol
Created April 9, 2021 16:04
Show Gist options
  • Save mariohmol/55f00f1f319c4e4365309fdd7e80cf73 to your computer and use it in GitHub Desktop.
Save mariohmol/55f00f1f319c4e4365309fdd7e80cf73 to your computer and use it in GitHub Desktop.
Arrays min max
const data = [
{total: 10, name: 'prod A'},
{total: 20, name: 'prod B'},
{total: 30, name: 'prod C'}
]
function sum(array){
let total=0
let max = array[0].total
let min = array[0].total
for(let i=0;i<data.length; i++){
const item = data[i];
total += item.total
if(item.total > max){
max = item.total
}
if(item.total < min){
min = item.total
}
}
return { total, max, min }
}
const total = sum(data)
console.log(total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment