I try to use map and reduce together to build a function where it loops through array of object and do some math but I got NAN. Why?
function getTotal(){
var obj = [
{
"name": "item 1",
"discount_price": 86.9,
"qty": 1,
},
{
"name": "item 2",
"discount_price": 11.9,
"qty": 1,
}
];
return obj.map(function(x){;return x.discounted_price * x.qty}).reduce(function(a,b){return a + b});
}
$('p').text(getTotal());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<p></p>