Created
April 9, 2021 16:04
-
-
Save mariohmol/55f00f1f319c4e4365309fdd7e80cf73 to your computer and use it in GitHub Desktop.
Arrays min max
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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