<!DOCTYPE html>
<html>
<head>
<script data-require="immutable.js@*" data-semver="3.7.6" src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.7.6/immutable.min.js"></script>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
// make console.log write to the page for better in-browser experience
(function () {
var body = document.querySelector('body');
body.style['fontFamily'] = 'monospace';
body.style['fontSize'] = '2em';
console.log = function (x) { body.innerText += x + '\n'; };
}());
///////////////////////////////////////////////////////////
let cart = Immutable.fromJS({
'items': [
{
'ASIN': 'B0008KLVVO',
'title': 'Paid in Full',
'price': 4.99
},
{
'ASIN': 'B00HAPTX42',
'title': 'Hello Nasty',
'price': 7.00
}
]
})
/**
const subtotal = cart.get('items').reduce((prev, curr, index) => {
console.log(`prev: ${prev}`)
console.log(`item ${index} price: ${curr.get('price')}`)
console.log(`subtotal: ${prev + curr.get('price')}`)
return prev += curr.get('price')
}, 0)
*/
const subtotal = cart.get('items').reduce((t, i) => t += i.get('price'), 0)
console.log(subtotal)
/* Styles go here */