Skip to content

Instantly share code, notes, and snippets.

@wuriyanto48
Last active April 11, 2017 10:48
Show Gist options
  • Save wuriyanto48/0f1558a54c75365483c924db1ef276ff to your computer and use it in GitHub Desktop.
Save wuriyanto48/0f1558a54c75365483c924db1ef276ff to your computer and use it in GitHub Desktop.
Find minimum value from object in Javascript
let price = {
"vendorPrice": 150000,
"normalPrice": 229000,
"pPrice": 90000,
"specialPrice": 169000,
"promoPrice": 0
};
function minPrice(prices){
let arrPrices = [];
for(let key in prices){
if(prices[key] == 0 || key == 'vendorPrice'){
continue;
}
arrPrices.push(prices[key]);
}
Array.min = function( array ){
return Math.min.apply( Math, array );
};
return Array.min(arrPrices);
}
console.log(minPrice(price));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment