Last active
April 11, 2017 10:48
-
-
Save wuriyanto48/0f1558a54c75365483c924db1ef276ff to your computer and use it in GitHub Desktop.
Find minimum value from object in Javascript
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
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